Class: Telegraph::Parser::Binding

Inherits:
Object
  • Object
show all
Defined in:
lib/telegraph/parser/binding.rb

Constant Summary collapse

BASE_URI =
'telegra.ph'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(article_id) ⇒ Binding

Returns a new instance of Binding.



10
11
12
# File 'lib/telegraph/parser/binding.rb', line 10

def initialize(article_id)
  self.article_id = article_id
end

Instance Attribute Details

#article_idObject

Returns the value of attribute article_id.



8
9
10
# File 'lib/telegraph/parser/binding.rb', line 8

def article_id
  @article_id
end

Instance Method Details

#contentObject



14
15
16
17
18
# File 'lib/telegraph/parser/binding.rb', line 14

def content
  Net::HTTP.get(BASE_URI, "/#{article_id}")
rescue EOFError
  ""
end

#image(src, prefix) ⇒ Object



20
21
22
23
# File 'lib/telegraph/parser/binding.rb', line 20

def image(src, prefix)
  src.gsub!('http://telegra.ph', '')
  { image_id(src, prefix) => open("http://#{BASE_URI}#{src}").read }
end

#image_id(src, prefix) ⇒ Object



25
26
27
28
# File 'lib/telegraph/parser/binding.rb', line 25

def image_id(src, prefix)
  src.gsub!('http://telegra.ph', '')
  "#{prefix}/#{File.basename(URI.parse("#{BASE_URI}#{src}").path)}"
end