Class: Tumblr::Data

Inherits:
Object
  • Object
show all
Defined in:
lib/tumblr.rb

Defined Under Namespace

Classes: Conversation, Link, Photo, Post, Posts, Quote, Regular, Tumblelog, Video

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc = nil) ⇒ Data

Returns a new instance of Data.



14
15
16
17
18
19
# File 'lib/tumblr.rb', line 14

def initialize(doc = nil)
  if doc
    @tumblelog = Tumblelog.new(REXML::XPath.first(doc, "//tumblelog"))
    @posts = Posts.new(REXML::XPath.first(doc, "//posts"), @tumblelog.timezone)
  end
end

Instance Attribute Details

#postsObject

Returns the value of attribute posts.



12
13
14
# File 'lib/tumblr.rb', line 12

def posts
  @posts
end

#tumblelogObject

Returns the value of attribute tumblelog.



12
13
14
# File 'lib/tumblr.rb', line 12

def tumblelog
  @tumblelog
end

Class Method Details

.load(path) ⇒ Object



21
22
23
# File 'lib/tumblr.rb', line 21

def self.load(path)
  new(REXML::Document.new(File.read(path)))
end

Instance Method Details

#<<(other) ⇒ Object



35
36
37
38
# File 'lib/tumblr.rb', line 35

def <<(other)
  @tumblelog = other.tumblelog unless @tumblelog
  @posts ? @posts.push(*other.posts) : @posts = other.posts
end

#save(path) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/tumblr.rb', line 25

def save(path)
  File.open(path, "w") do |file|
    doc = REXML::Document.new
    root = doc.add_element "ruby-tumblr", {"version" => "0.1"}
    root.elements << @tumblelog.to_xml if @tumblelog
    root.elements << @posts.to_xml if @posts
    doc.write(file)
  end
end