Class: Typesensual::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/typesensual/field.rb

Instance Method Summary collapse

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

Returns:

  • (Boolean)


9
10
11
# File 'lib/typesensual/field.rb', line 9

def facet?
  @field['facet']
end

#index?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/typesensual/field.rb', line 13

def index?
  @field['index']
end

#infix?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/typesensual/field.rb', line 17

def infix?
  @field['infix']
end

#localeObject



21
22
23
# File 'lib/typesensual/field.rb', line 21

def locale
  @field['locale'].presence
end

#nameObject



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

Returns:

  • (Boolean)


33
34
35
# File 'lib/typesensual/field.rb', line 33

def optional?
  @field['optional']
end

#sort?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/typesensual/field.rb', line 37

def sort?
  @field['sort']
end

#to_hObject



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

#typeObject



41
42
43
# File 'lib/typesensual/field.rb', line 41

def type
  @field['type']
end