Class: Telegraph::Parser::Binding
- Inherits:
-
Object
- Object
- Telegraph::Parser::Binding
- Defined in:
- lib/telegraph/parser/binding.rb
Constant Summary collapse
- BASE_URI =
'telegra.ph'
Instance Attribute Summary collapse
-
#article_id ⇒ Object
Returns the value of attribute article_id.
Instance Method Summary collapse
- #content ⇒ Object
- #image(src, prefix) ⇒ Object
- #image_id(src, prefix) ⇒ Object
-
#initialize(article_id) ⇒ Binding
constructor
A new instance of Binding.
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_id ⇒ Object
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
#content ⇒ Object
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 |