Class: ModalFields::FieldDeclaration
- Inherits:
-
Struct
- Object
- Struct
- ModalFields::FieldDeclaration
- Defined in:
- lib/modalfields/modalfields.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#name ⇒ Object
Returns the value of attribute name.
-
#specifiers ⇒ Object
Returns the value of attribute specifiers.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #add!(attrs) ⇒ Object
- #remove_attributes!(*attrs) ⇒ Object
- #replace!(replacements = {}) ⇒ Object
- #to_s ⇒ Object
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes
27 28 29 |
# File 'lib/modalfields/modalfields.rb', line 27 def attributes @attributes end |
#name ⇒ Object
Returns the value of attribute name
27 28 29 |
# File 'lib/modalfields/modalfields.rb', line 27 def name @name end |
#specifiers ⇒ Object
Returns the value of attribute specifiers
27 28 29 |
# File 'lib/modalfields/modalfields.rb', line 27 def specifiers @specifiers end |
#type ⇒ Object
Returns the value of attribute type
27 28 29 |
# File 'lib/modalfields/modalfields.rb', line 27 def type @type end |
Class Method Details
.declare(name, type, *args) ⇒ Object
29 30 31 32 |
# File 'lib/modalfields/modalfields.rb', line 29 def self.declare(name, type, *args) attributes = args. new(name, type, args, attributes) end |
Instance Method Details
#add!(attrs) ⇒ Object
46 47 48 49 |
# File 'lib/modalfields/modalfields.rb', line 46 def add!(attrs) self.attributes.merge! attrs self end |
#remove_attributes!(*attrs) ⇒ Object
41 42 43 44 |
# File 'lib/modalfields/modalfields.rb', line 41 def remove_attributes!(*attrs) self.attributes = self.attributes.except(*attrs) self end |
#replace!(replacements = {}) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/modalfields/modalfields.rb', line 34 def replace!(replacements={}) replacements.each_pair do |key, value| self[key] = value end self end |
#to_s ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/modalfields/modalfields.rb', line 51 def to_s code = "#{name} :#{type}" code << ", "+specifiers.inspect[1...-1] unless specifiers.empty? unless attributes.empty? code << ", "+attributes.keys.sort_by{|attr| attr.to_s}.map{|attr| v = attributes[attr] v = v.kind_of?(BigDecimal) ? "BigDecimal('#{v.to_s}')" : v.inspect ":#{attr}=>#{v}" }*", " end code end |