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
29 30 31 |
# File 'lib/modalfields/modalfields.rb', line 29 def attributes @attributes end |
#name ⇒ Object
Returns the value of attribute name
29 30 31 |
# File 'lib/modalfields/modalfields.rb', line 29 def name @name end |
#specifiers ⇒ Object
Returns the value of attribute specifiers
29 30 31 |
# File 'lib/modalfields/modalfields.rb', line 29 def specifiers @specifiers end |
#type ⇒ Object
Returns the value of attribute type
29 30 31 |
# File 'lib/modalfields/modalfields.rb', line 29 def type @type end |
Class Method Details
.declare(name, type, *args) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/modalfields/modalfields.rb', line 31 def self.declare(name, type, *args) attributes = args. required = attributes.delete(:required) args << :required if required new(name, type, args, attributes) end |
Instance Method Details
#add!(attrs) ⇒ Object
50 51 52 53 |
# File 'lib/modalfields/modalfields.rb', line 50 def add!(attrs) self.attributes.merge! attrs self end |
#remove_attributes!(*attrs) ⇒ Object
45 46 47 48 |
# File 'lib/modalfields/modalfields.rb', line 45 def remove_attributes!(*attrs) self.attributes = self.attributes.except(*attrs) self end |
#replace!(replacements = {}) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/modalfields/modalfields.rb', line 38 def replace!(replacements={}) replacements.each_pair do |key, value| self[key] = value end self end |
#to_s ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/modalfields/modalfields.rb', line 55 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 |