Class: Shaf::Formable::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/shaf/formable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, params = {}) ⇒ Field

Returns a new instance of Field.



6
7
8
9
10
11
12
# File 'lib/shaf/formable.rb', line 6

def initialize(name, params = {})
  @name = name
  @type = params[:type]
  @label = params[:label]
  @has_value = params.key? :value
  @value = params[:value]
end

Instance Attribute Details

#labelObject (readonly)

Returns the value of attribute label.



4
5
6
# File 'lib/shaf/formable.rb', line 4

def label
  @label
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/shaf/formable.rb', line 4

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'lib/shaf/formable.rb', line 4

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



4
5
6
# File 'lib/shaf/formable.rb', line 4

def value
  @value
end

Instance Method Details

#has_value?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/shaf/formable.rb', line 14

def has_value?
  @has_value
end

#to_htmlObject



18
19
20
21
22
23
24
25
# File 'lib/shaf/formable.rb', line 18

def to_html
  [
    '<div class="form--input-group">',
    label_element,
    input_element,
    '</div>'
  ].compact.join("\n")
end