Class: Stylegen::Data

Inherits:
Object
  • Object
show all
Defined in:
lib/stylegen/data.rb

Instance Method Summary collapse

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_levelObject



60
61
62
# File 'lib/stylegen/data.rb', line 60

def access_level
  @data['access_level'] || 'internal'
end

#basenameObject



56
57
58
# File 'lib/stylegen/data.rb', line 56

def basename
  File.basename(@data['output_path'])
end

#color_entriesObject



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_levelObject



64
65
66
# File 'lib/stylegen/data.rb', line 64

def effective_access_level
  access_level == 'internal' ? '' : "#{access_level} "
end

#file_headerObject



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

#inflectorObject



13
14
15
# File 'lib/stylegen/data.rb', line 13

def inflector
  @inflector ||= Dry::Inflector.new
end

#output_pathObject



48
49
50
# File 'lib/stylegen/data.rb', line 48

def output_path
  @data['output_path']
end

#struct_nameObject



68
69
70
# File 'lib/stylegen/data.rb', line 68

def struct_name
  "#{system_name}Color"
end

#swiftui?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/stylegen/data.rb', line 52

def swiftui?
  @data['swiftui'] || false
end

#system_nameObject



40
41
42
# File 'lib/stylegen/data.rb', line 40

def system_name
  @data['system_name'] || 'Theme'
end

#util_method_nameObject



44
45
46
# File 'lib/stylegen/data.rb', line 44

def util_method_name
  inflector.camelize_lower(inflector.underscore(system_name))
end

#versionObject



36
37
38
# File 'lib/stylegen/data.rb', line 36

def version
  Stylegen::VERSION
end