Class: Factual::Fact

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

Overview

This class holds the subject_key, value, field_ref field (field metadata in hash). The input method is for suggesting a new value for the fact.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

:nodoc:



296
297
298
299
300
301
302
303
# File 'lib/factual.rb', line 296

def initialize(table, subject_key, field, value) # :nodoc:
  @value = value 
  @field = field
  @subject_key = subject_key

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

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



294
295
296
# File 'lib/factual.rb', line 294

def field
  @field
end

#field_refObject (readonly)

:nodoc:



305
306
307
# File 'lib/factual.rb', line 305

def field_ref
  @field_ref
end

#subject_keyObject (readonly)

Returns the value of attribute subject_key.



294
295
296
# File 'lib/factual.rb', line 294

def subject_key
  @subject_key
end

#valueObject (readonly)

Returns the value of attribute value.



294
295
296
# File 'lib/factual.rb', line 294

def value
  @value
end

Instance Method Details

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

To input a new value to the fact

Parameters:

* +value+ 
* <tt>opts[:source]</tt> the source of an input, can be a URL or something else
* <tt>opts[:comments]</tt> the comments of an input

Sample:

fact.input('new value', :source => 'http://website.com', :comments => 'because it is new value.'


318
319
320
321
322
323
324
325
326
327
328
329
330
# File 'lib/factual.rb', line 318

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

  hash = opts.merge({
    :subjectKey => @subject_key.first,
    :values     => [{
      :fieldId    => @field['id'],
      :value      => value }]
  })

  @adapter.input(@table_key, hash)
  return true
end

#inspectObject

Just return the value



338
339
340
# File 'lib/factual.rb', line 338

def inspect
  @value
end

#to_sObject

Just return the value



333
334
335
# File 'lib/factual.rb', line 333

def to_s
  @value
end