Skip to content

Commit d3e8b8a

Browse files
committed
feat: add Parse module to simplify
Sort structure
1 parent f09237e commit d3e8b8a

File tree

7 files changed

+34
-24
lines changed

7 files changed

+34
-24
lines changed

lib/rootfs/distro/ubuntu.rb

+5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
# frozen_string_literal: true
22

3+
require_relative "../http"
4+
require_relative "../data"
35
require_relative "ubuntu/arch"
46
require_relative "ubuntu/edition"
7+
require_relative "ubuntu/file"
58
require_relative "ubuntu/url"
69

710
module RootFS
811
module Distro
912
module Ubuntu
13+
extend self
14+
1015
Methods = {
1116
arch?: ARCH,
1217
edition?: EDITION,

lib/rootfs/distro/ubuntu/arch.rb

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
require_relative "../../parse"
4+
35
module RootFS
46
module Distro
57
module Ubuntu
@@ -15,16 +17,7 @@ module Ubuntu
1517
].freeze
1618

1719
def parse_arch(any)
18-
err_msg = "Valid Ubuntu arch: #{ARCH}"
19-
20-
puts err_msg unless any
21-
22-
str = any.to_s
23-
puts err_msg if str.empty?
24-
25-
return { arch: str } if ARCH.include?(str)
26-
27-
puts err_msg
20+
RootFS::Parse._str_in_arr(any, "Ubuntu", "arch", ARCH)
2821
end
2922
end
3023
end

lib/rootfs/distro/ubuntu/edition.rb

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
require_relative "../../parse"
4+
35
module RootFS
46
module Distro
57
module Ubuntu
@@ -42,16 +44,7 @@ module Ubuntu
4244
CODENAME_VERSION = {}.merge(DEV, INTERIM, LTS, ESM).freeze
4345

4446
def parse_edition(any)
45-
err_msg = "Valid Ubuntu edition: #{EDITION}"
46-
47-
puts err_msg unless any
48-
49-
str = any.to_s
50-
puts err_msg if str.empty?
51-
52-
return { edition: str } if EDITION.include?(str)
53-
54-
puts err_msg
47+
RootFS::Parse._str_in_arr(any, "Ubuntu", "edition", EDITION)
5548
end
5649

5750
def parse_release(any)

lib/rootfs/distro/ubuntu/file.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# frozen_string_literal: true
22

3-
require_relative "../../http"
4-
require_relative "../../data"
3+
require_relative "../ubuntu"
54

65
module RootFS
76
module Distro

lib/rootfs/distro/ubuntu/file_test.rb

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class MyClass
1111

1212
p u.files_of
1313
p u.files_of("desktop", 20.04)
14+
p u.files_of("desktop", 22.04, daily: true)
1415
p u.files_of("desktop", 23.04)
1516
p u.files_of("desktop", "lunar")
1617
p u.files_of("server", 20.04)

lib/rootfs/distro/ubuntu/url.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# frozen_string_literal: true
22

3-
require_relative "edition"
4-
require_relative "arch"
3+
require_relative "../ubuntu"
54

65
module RootFS
76
module Distro

lib/rootfs/parse.rb

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# frozen_string_literal: true
2+
3+
module RootFS
4+
module Parse
5+
extend self
6+
7+
def _str_in_arr(any, distro, attr, data)
8+
err_msg = "Valid #{distro} #{attr}: #{data}"
9+
10+
puts err_msg unless any
11+
12+
str = any.to_s
13+
puts err_msg if str.empty?
14+
15+
return { "#{attr}": str } if data.include?(str)
16+
17+
puts err_msg
18+
end
19+
end
20+
end

0 commit comments

Comments
 (0)