Class: HParser::Inline::Fotolife
- Inherits:
-
Object
- Object
- HParser::Inline::Fotolife
- Includes:
- Collectable
- Defined in:
- lib/hparser/html.rb,
lib/hparser/text.rb,
lib/hparser/latex.rb,
lib/hparser/inline/fotolife.rb
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#ext ⇒ Object
readonly
Returns the value of attribute ext.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Class Method Summary collapse
Instance Method Summary collapse
- #==(o) ⇒ Object
- #image_url ⇒ Object
-
#initialize(id, date, time, ext) ⇒ Fotolife
constructor
A new instance of Fotolife.
- #to_html ⇒ Object
- #to_latex ⇒ Object
- #to_text ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(id, date, time, ext) ⇒ Fotolife
Returns a new instance of Fotolife.
12 13 14 15 16 17 |
# File 'lib/hparser/inline/fotolife.rb', line 12 def initialize(id, date, time, ext) @id = id @date = date @time = time @ext = ext end |
Instance Attribute Details
#date ⇒ Object (readonly)
Returns the value of attribute date.
11 12 13 |
# File 'lib/hparser/inline/fotolife.rb', line 11 def date @date end |
#ext ⇒ Object (readonly)
Returns the value of attribute ext.
11 12 13 |
# File 'lib/hparser/inline/fotolife.rb', line 11 def ext @ext end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
11 12 13 |
# File 'lib/hparser/inline/fotolife.rb', line 11 def id @id end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
11 12 13 |
# File 'lib/hparser/inline/fotolife.rb', line 11 def time @time end |
Class Method Details
.parse(scanner, context = nil) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/hparser/inline/fotolife.rb', line 27 def self.parse(scanner, context=nil) if scanner.scan(/\[f:id:([^:]+):(\d{8})(\d{6})(p|g|j):image(:[^\]]+)?\]/) then Fotolife.new scanner[1], scanner[2], scanner[3], scanner[4] == 'j' ? 'jpg' : scanner[4] == 'p' ? 'png' : 'gif' end end |
Instance Method Details
#==(o) ⇒ Object
34 35 36 37 |
# File 'lib/hparser/inline/fotolife.rb', line 34 def ==(o) self.class == o.class and @id == o.id and @date == o.date and @time == o.time and @ext == o.ext end |
#image_url ⇒ Object
23 24 25 |
# File 'lib/hparser/inline/fotolife.rb', line 23 def image_url "http://f.hatena.ne.jp/images/fotolife/#{id[0..0]}/#{id}/#{@date}/#{@date}#{@time}.#{@ext}" end |
#to_html ⇒ Object
319 320 321 |
# File 'lib/hparser/html.rb', line 319 def to_html %(<a href="#{self.url}"><img src="#{self.image_url}"></a>) end |
#to_latex ⇒ Object
248 249 250 |
# File 'lib/hparser/latex.rb', line 248 def to_latex alias_method :to_latex,:url end |
#to_text ⇒ Object
160 |
# File 'lib/hparser/text.rb', line 160 alias_method :to_text,:url |
#url ⇒ Object
19 20 21 |
# File 'lib/hparser/inline/fotolife.rb', line 19 def url "http://f.hatena.ne.jp/#{@id}/#{@date}#{@time}" end |