Class: Typesensual::Field
- Inherits:
-
Object
- Object
- Typesensual::Field
- Defined in:
- lib/typesensual/field.rb
Instance Method Summary collapse
- #facet? ⇒ Boolean
- #index? ⇒ Boolean
- #infix? ⇒ Boolean
-
#initialize(hash) ⇒ Field
constructor
A new instance of Field.
- #locale ⇒ Object
- #name ⇒ Object
- #optional? ⇒ Boolean
- #sort? ⇒ Boolean
- #to_h ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(hash) ⇒ Field
Returns a new instance of Field.
5 6 7 |
# File 'lib/typesensual/field.rb', line 5 def initialize(hash) @field = hash.stringify_keys end |
Instance Method Details
#facet? ⇒ Boolean
9 10 11 |
# File 'lib/typesensual/field.rb', line 9 def facet? @field['facet'] end |
#index? ⇒ Boolean
13 14 15 |
# File 'lib/typesensual/field.rb', line 13 def index? @field['index'] end |
#infix? ⇒ Boolean
17 18 19 |
# File 'lib/typesensual/field.rb', line 17 def infix? @field['infix'] end |
#locale ⇒ Object
21 22 23 |
# File 'lib/typesensual/field.rb', line 21 def locale @field['locale'].presence end |
#name ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/typesensual/field.rb', line 25 def name if @field['name'].is_a?(Regexp) @field['name'].source else @field['name'].to_s end end |
#optional? ⇒ Boolean
33 34 35 |
# File 'lib/typesensual/field.rb', line 33 def optional? @field['optional'] end |
#sort? ⇒ Boolean
37 38 39 |
# File 'lib/typesensual/field.rb', line 37 def sort? @field['sort'] end |
#to_h ⇒ Object
45 46 47 48 49 50 |
# File 'lib/typesensual/field.rb', line 45 def to_h @field.to_h.merge( 'name' => name, 'locale' => locale ).compact! end |
#type ⇒ Object
41 42 43 |
# File 'lib/typesensual/field.rb', line 41 def type @field['type'] end |