Class: ModalFields::FieldDeclaration

Inherits:
Struct
  • Object
show all
Defined in:
lib/modalfields/modalfields.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes

Returns:

  • (Object)

    the current value of attributes



29
30
31
# File 'lib/modalfields/modalfields.rb', line 29

def attributes
  @attributes
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



29
30
31
# File 'lib/modalfields/modalfields.rb', line 29

def name
  @name
end

#specifiersObject

Returns the value of attribute specifiers

Returns:

  • (Object)

    the current value of specifiers



29
30
31
# File 'lib/modalfields/modalfields.rb', line 29

def specifiers
  @specifiers
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of 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.extract_options!
  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_sObject



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