Class: Factual::Fact

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table, subject_key, field, value) ⇒ Fact

Returns a new instance of Fact.



121
122
123
124
125
126
127
128
# File 'lib/factual.rb', line 121

def initialize(table, subject_key, field, value)
  @value = value 
  @field = field
  @subject_key = subject_key

  @table_key = table.key
  @adapter   = table.adapter
end

Instance Attribute Details

#adapterObject

Returns the value of attribute adapter.



119
120
121
# File 'lib/factual.rb', line 119

def adapter
  @adapter
end

#fieldObject

Returns the value of attribute field.



119
120
121
# File 'lib/factual.rb', line 119

def field
  @field
end

#subject_keyObject

Returns the value of attribute subject_key.



119
120
121
# File 'lib/factual.rb', line 119

def subject_key
  @subject_key
end

#valueObject

Returns the value of attribute value.



119
120
121
# File 'lib/factual.rb', line 119

def value
  @value
end

Instance Method Details

#field_refObject



130
131
132
# File 'lib/factual.rb', line 130

def field_ref
  @field["field_ref"]
end

#input(value, opts = {}) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/factual.rb', line 134

def input(value, opts={})
  return false if value.nil?

  hash = opts.merge({
    :subjectKey => @subject_key,
    :fieldId => @field['id'],
    :value => value
  })
  query_string = hash.to_a.collect{ |k,v| URI.escape(k.to_s) + '=' + URI.escape(v.to_s) }.join('&')

  @adapter.api_call("/tables/#{@table_key}/input.js?" + query_string)
  return true
end

#inspectObject



152
153
154
# File 'lib/factual.rb', line 152

def inspect
  @value
end

#to_sObject



148
149
150
# File 'lib/factual.rb', line 148

def to_s
  @value
end