Class: Csquery::FieldValue

Inherits:
Object
  • Object
show all
Defined in:
lib/csquery/field_value.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value:, name: nil) ⇒ FieldValue

Returns a new instance of FieldValue.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/csquery/field_value.rb', line 5

def initialize(value:, name: nil)
  value = value[0] if value.is_a?(Array) and value[0].is_a?(Hash)

  if value.is_a?(Hash)
    @name = value.keys[0]
    @value = Structured.format_value(value.values[0])
  else
    @name = name
    @value = Structured.format_value(value)
  end
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/csquery/field_value.rb', line 3

def name
  @name
end

#valueObject (readonly)

Returns the value of attribute value.



3
4
5
# File 'lib/csquery/field_value.rb', line 3

def value
  @value
end

Instance Method Details

#to_sObject



23
24
25
# File 'lib/csquery/field_value.rb', line 23

def to_s
  to_value
end

#to_valueObject



17
18
19
20
21
# File 'lib/csquery/field_value.rb', line 17

def to_value
  return "#{@name}:#{@value}" if @name

  @value
end