class HatenaFotolife::Image

Attributes

id[R]
image_uri[R]
image_uri_medium[R]
image_uri_small[R]
title[R]
uri[R]

Public Class Methods

load_xml(xml) click to toggle source

Create a new image from a XML string. @param [String] xml XML string representation @return [HatenaFotolife::Image]

# File lib/hatena_fotolife/image.rb, line 12
def self.load_xml(xml)
  HatenaFotolife::Image.new(xml)
end
new(xml) click to toggle source
# File lib/hatena_fotolife/image.rb, line 23
def initialize(xml)
  @document = Nokogiri::XML(xml)
  parse_document
end

Public Instance Methods

to_xml() click to toggle source

@return [String]

# File lib/hatena_fotolife/image.rb, line 17
def to_xml
  @document.to_s.gsub(/\"/, "'")
end

Private Instance Methods

parse_document() click to toggle source
# File lib/hatena_fotolife/image.rb, line 28
def parse_document
  @edit_uri                  = @document.at_css('link[@rel="service.edit"]')['href'].to_s
  @id                        = @edit_uri.split('/').last
  @title                     = @document.at_css('title').content
  @uri                       = @document.at_css('link[@rel="alternate"]')['href'].to_s
  @issued                    = @document.at_css('issued').content
  @image_uri                 = @document.xpath('//hatena:imageurl/text()').to_s
  @image_uri_small           = @document.xpath('//hatena:imageurlsmall/text()').to_s
  @image_uri_medium          = @document.xpath('//hatena:imageurlmedium/text()').to_s
  @author_name               = @document.at_css('author name').content
end