Class: StylesTemplate
- Inherits:
-
Object
- Object
- StylesTemplate
- Defined in:
- lib/admiral-tools-figma/helper/figma/figma_template_generator/models/styles_template.rb
Instance Attribute Summary collapse
-
#common_style_names ⇒ Object
Returns the value of attribute common_style_names.
-
#groups ⇒ Object
Returns the value of attribute groups.
-
#styles ⇒ Object
Returns the value of attribute styles.
Instance Method Summary collapse
-
#initialize(styles:) ⇒ StylesTemplate
constructor
A new instance of StylesTemplate.
- #to_hash ⇒ Object
Constructor Details
#initialize(styles:) ⇒ StylesTemplate
Returns a new instance of StylesTemplate.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/admiral-tools-figma/helper/figma/figma_template_generator/models/styles_template.rb', line 8 def initialize(styles:) styles = styles.sort_by(&:name) @styles = styles groups_hash = {} styles.each do |s| group = groups_hash[s.name_info.group_name] || StylesGroup.new(name: s.name_info.group_name, styles: []) group.styles.push(s) groups_hash[s.name_info.group_name] = group end @groups = groups_hash.map { |_key, value| value } @common_style_names = styles .uniq { |s| s.name_info.style_name } .map { |s| s.name_info.style_name } end |
Instance Attribute Details
#common_style_names ⇒ Object
Returns the value of attribute common_style_names.
6 7 8 |
# File 'lib/admiral-tools-figma/helper/figma/figma_template_generator/models/styles_template.rb', line 6 def common_style_names @common_style_names end |
#groups ⇒ Object
Returns the value of attribute groups.
6 7 8 |
# File 'lib/admiral-tools-figma/helper/figma/figma_template_generator/models/styles_template.rb', line 6 def groups @groups end |
#styles ⇒ Object
Returns the value of attribute styles.
6 7 8 |
# File 'lib/admiral-tools-figma/helper/figma/figma_template_generator/models/styles_template.rb', line 6 def styles @styles end |
Instance Method Details
#to_hash ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/admiral-tools-figma/helper/figma/figma_template_generator/models/styles_template.rb', line 27 def to_hash hash = {} hash['styles'] = styles.map(&:to_hash) hash['groups'] = groups.map(&:to_hash) hash['common_style_names'] = common_style_names hash end |