Class: Zemanta::Markup

Inherits:
Object
  • Object
show all
Defined in:
lib/zemanta/markup.rb,
lib/zemanta/markup/link.rb,
lib/zemanta/markup/link/target.rb

Defined Under Namespace

Classes: Link

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Markup

Returns a new instance of Markup.



6
7
8
9
# File 'lib/zemanta/markup.rb', line 6

def initialize(opts = {})
  @text  = opts["text"]
  @links = opts["links"].map{ |link| Link.new(link) }
end

Instance Attribute Details

Returns the value of attribute links.



4
5
6
# File 'lib/zemanta/markup.rb', line 4

def links
  @links
end

#textObject (readonly)

Returns the value of attribute text.



4
5
6
# File 'lib/zemanta/markup.rb', line 4

def text
  @text
end

Class Method Details

.fetch(text, opts = {}) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/zemanta/markup.rb', line 11

def self.fetch(text, opts = {})
  relevance  = opts.delete(:relevance)  || 0
  confidence = opts.delete(:confidence) || 0

  new(suggest_markup_request(text, opts)).tap do |markup|
    markup.drop_links_below(relevance, confidence)
  end
end

Instance Method Details



20
21
22
23
24
# File 'lib/zemanta/markup.rb', line 20

def drop_links_below(relevance, confidence)
  @links.keep_if do |link|
    link.above?(relevance, confidence)
  end
end