Class: Typelizer::Shape
- Inherits:
-
Object
- Object
- Typelizer::Shape
- Defined in:
- lib/typelizer/shape.rb
Instance Attribute Summary collapse
-
#fingerprint ⇒ Object
readonly
Returns the value of attribute fingerprint.
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
-
#initialize(properties:) ⇒ Shape
constructor
A new instance of Shape.
- #inspect ⇒ Object
- #map_properties ⇒ Object
- #render(sort_order: :none, prefer_double_quotes: false) ⇒ Object (also: #to_s)
Constructor Details
#initialize(properties:) ⇒ Shape
Returns a new instance of Shape.
7 8 9 10 11 12 |
# File 'lib/typelizer/shape.rb', line 7 def initialize(properties:) @properties = properties.freeze @fingerprint = ["Shape", properties.map(&:fingerprint)].freeze @hash = @fingerprint.hash freeze end |
Instance Attribute Details
#fingerprint ⇒ Object (readonly)
Returns the value of attribute fingerprint.
28 29 30 |
# File 'lib/typelizer/shape.rb', line 28 def fingerprint @fingerprint end |
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
28 29 30 |
# File 'lib/typelizer/shape.rb', line 28 def hash @hash end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
5 6 7 |
# File 'lib/typelizer/shape.rb', line 5 def properties @properties end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
30 31 32 |
# File 'lib/typelizer/shape.rb', line 30 def ==(other) other.is_a?(Shape) && fingerprint == other.fingerprint end |
#inspect ⇒ Object
35 36 37 |
# File 'lib/typelizer/shape.rb', line 35 def inspect "<Typelizer::Shape properties=#{properties.inspect}>" end |
#map_properties ⇒ Object
14 15 16 |
# File 'lib/typelizer/shape.rb', line 14 def map_properties self.class.new(properties: properties.map { |p| yield p }) end |
#render(sort_order: :none, prefer_double_quotes: false) ⇒ Object Also known as: to_s
18 19 20 21 22 23 24 |
# File 'lib/typelizer/shape.rb', line 18 def render(sort_order: :none, prefer_double_quotes: false) inner = properties.map { |p| (p.render(sort_order: sort_order, prefer_double_quotes: prefer_double_quotes) + ";") .gsub(/^/, " ") }.join("\n") "{\n#{inner}\n}" end |