Class: HParser::Inline::Fotolife

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#dateObject (readonly)

Returns the value of attribute date.



11
12
13
# File 'lib/hparser/inline/fotolife.rb', line 11

def date
  @date
end

#extObject (readonly)

Returns the value of attribute ext.



11
12
13
# File 'lib/hparser/inline/fotolife.rb', line 11

def ext
  @ext
end

#idObject (readonly)

Returns the value of attribute id.



11
12
13
# File 'lib/hparser/inline/fotolife.rb', line 11

def id
  @id
end

#timeObject (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_urlObject



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_htmlObject



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_latexObject



248
249
250
# File 'lib/hparser/latex.rb', line 248

def to_latex
  alias_method :to_latex,:url
end

#to_textObject



160
# File 'lib/hparser/text.rb', line 160

alias_method :to_text,:url

#urlObject



19
20
21
# File 'lib/hparser/inline/fotolife.rb', line 19

def url
  "http://f.hatena.ne.jp/#{@id}/#{@date}#{@time}"
end