Class: Stylegen::Data
- Inherits:
-
Object
- Object
- Stylegen::Data
- Defined in:
- lib/stylegen/data.rb
Instance Method Summary collapse
- #access_level ⇒ Object
- #basename ⇒ Object
- #color_entries ⇒ Object
- #effective_access_level ⇒ Object
- #file_header ⇒ Object
- #inflector ⇒ Object
-
#initialize(data) ⇒ Data
constructor
A new instance of Data.
- #output_path ⇒ Object
- #struct_name ⇒ Object
- #swiftui? ⇒ Boolean
- #system_name ⇒ Object
- #util_method_name ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(data) ⇒ Data
Returns a new instance of Data.
9 10 11 |
# File 'lib/stylegen/data.rb', line 9 def initialize(data) @data = data end |
Instance Method Details
#access_level ⇒ Object
60 61 62 |
# File 'lib/stylegen/data.rb', line 60 def access_level @data['access_level'] || 'internal' end |
#basename ⇒ Object
56 57 58 |
# File 'lib/stylegen/data.rb', line 56 def basename File.basename(@data['output_path']) end |
#color_entries ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/stylegen/data.rb', line 72 def color_entries @color_entries ||= @data['colors'].map do |key, value| { property: inflector.camelize_lower(key), description: value['description'], color: generate_color(value) } end end |
#effective_access_level ⇒ Object
64 65 66 |
# File 'lib/stylegen/data.rb', line 64 def effective_access_level access_level == 'internal' ? '' : "#{access_level} " end |
#file_header ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/stylegen/data.rb', line 17 def file_header header = @data['header'] || <<~HEADER // // {{STYLEGEN_FILENAME}} // // Autogenerated by stylegen ({{STYLEGEN_VERSION}}) // DO NOT EDIT // HEADER replacements = { 'STYLEGEN_FILENAME' => basename, 'STYLEGEN_VERSION' => version, 'STYLEGEN_YEAR' => Date.today.year } header.strip.gsub(/{{(\w+)}}/) { replacements[Regexp.last_match(1)] || '' } end |
#inflector ⇒ Object
13 14 15 |
# File 'lib/stylegen/data.rb', line 13 def inflector @inflector ||= Dry::Inflector.new end |
#output_path ⇒ Object
48 49 50 |
# File 'lib/stylegen/data.rb', line 48 def output_path @data['output_path'] end |
#struct_name ⇒ Object
68 69 70 |
# File 'lib/stylegen/data.rb', line 68 def struct_name "#{system_name}Color" end |
#swiftui? ⇒ Boolean
52 53 54 |
# File 'lib/stylegen/data.rb', line 52 def swiftui? @data['swiftui'] || false end |
#system_name ⇒ Object
40 41 42 |
# File 'lib/stylegen/data.rb', line 40 def system_name @data['system_name'] || 'Theme' end |
#util_method_name ⇒ Object
44 45 46 |
# File 'lib/stylegen/data.rb', line 44 def util_method_name inflector.camelize_lower(inflector.underscore(system_name)) end |