Class: Archimate::DataModel::Color
- Inherits:
-
ArchimateNode
- Object
- Dry::Struct
- ArchimateNode
- Archimate::DataModel::Color
- Defined in:
- lib/archimate/data_model/color.rb
Overview
RGBColorType in the XSD RGB Color type. The r, g, b attributes range from 0 - 255. The a (alpha) transparency attribute is optional. 0 = full transparency, 100 = opaque.
Instance Attribute Summary
Attributes inherited from ArchimateNode
#parent_attribute_name, #struct_instance_variables
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from ArchimateNode
#ancestors, #build_index, #clone, #compact!, #delete, #diff, #dup, #element_by_id, #id, #in_model, #in_model=, #initialize, #parent, #parent=, #path, #primitive?, #referenced_identified_nodes, #set, #with
Constructor Details
This class inherits a constructor from Archimate::DataModel::ArchimateNode
Class Method Details
.black ⇒ Object
26 27 28 |
# File 'lib/archimate/data_model/color.rb', line 26 def self.black new(r: 0, g: 0, b: 0, a: 100) end |
.rgba(str) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/archimate/data_model/color.rb', line 14 def self.rgba(str) return nil if str.nil? md = str.match(/#([\da-f]{2})([\da-f]{2})([\da-f]{2})([\da-f]{2})?/) return nil unless md new( r: md[1].to_i(16), g: md[2].to_i(16), b: md[3].to_i(16), a: md[4].nil? ? 100 : (md[4].to_i(16) / 256.0 * 100.0).to_i ) end |
Instance Method Details
#to_rgba ⇒ Object
34 35 36 |
# File 'lib/archimate/data_model/color.rb', line 34 def to_rgba a == 100 ? format("#%02x%02x%02x", r, g, b) : format("#%02x%02x%02x%02x", r, g, b, scaled_alpha) end |
#to_s ⇒ Object
30 31 32 |
# File 'lib/archimate/data_model/color.rb', line 30 def to_s "Color(r: #{r}, g: #{g}, b: #{b}, a: #{a})" end |