Class: Smartfm::Item

Inherits:
Base
  • Object
show all
Includes:
ActsAsLikable, MediaSupport, PublicContent
Defined in:
lib/smartfm/models/item.rb

Defined Under Namespace

Classes: Cue, Response

Constant Summary collapse

ATTRIBUTES =
[:sentences, :responses, :cue, :id, :list, :user]
READONLY_ATTRIBUTES =
[:sentences, :responses, :cue, :id, :user]

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ActsAsLikable

#like!, #likes, #unlike!

Methods included from MediaSupport

#add_image, #add_sound, #attribution_params

Methods included from PublicContent

included

Methods inherited from Base

attributes, #attributes

Constructor Details

#initialize(params = {}) ⇒ Item

Returns a new instance of Item.



44
45
46
47
48
49
50
51
52
# File 'lib/smartfm/models/item.rb', line 44

def initialize(params = {})
  params[:responses] = [params[:response]] if params[:response]
  @id        = params[:id].to_i
  @list      = params[:list]
  @cue       = self.deserialize(params[:cue],       :as => Smartfm::Item::Cue)
  @responses = self.deserialize(params[:responses], :as => Smartfm::Item::Response)
  @sentences = self.deserialize(params[:sentences], :as => Smartfm::Sentence)
  @user      = self.deserialize(params[:user],      :as => Smartfm::User)
end

Class Method Details

.extract(text, params = {}) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/smartfm/models/item.rb', line 54

def self.extract(text, params = {})
  params[:text] = text
  hash = self.rest_client.extract(params)
  if params[:words_only] == false
    self.deserialize(hash) || []
  else
    hash
  end
end

.rest_clientObject



11
# File 'lib/smartfm/models/item.rb', line 11

def self.rest_client; Smartfm::RestClient::Item; end

Instance Method Details

#add_tags(auth, *tags) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/smartfm/models/item.rb', line 64

def add_tags(auth, *tags)
  post_params = {}
  tags.each_with_index do |tag, idx|
    if tag.is_a?(String)
      post_params["semantic_tags[#{idx}][name]"] = tag
    else
      post_params["semantic_tags[#{idx}][name]"] = tag[:name]
      post_params["semantic_tags[#{idx}][disambiguation]"] = tag[:disambiguation]
    end
  end
  self.rest_client.add_tags(auth, post_params.merge(:id => self.id))
end

#rest_clientObject



12
# File 'lib/smartfm/models/item.rb', line 12

def rest_client; self.class.rest_client; end