Class: Hatenablog::Entry
- Inherits:
-
Object
- Object
- Hatenablog::Entry
- Extended by:
- AfterHook
- Defined in:
- lib/hatenablog/entry.rb
Instance Attribute Summary collapse
-
#author_name ⇒ Object
Returns the value of attribute author_name.
- #categories ⇒ Array
-
#content ⇒ Object
Returns the value of attribute content.
-
#draft ⇒ Object
Returns the value of attribute draft.
-
#edit_uri ⇒ Object
Returns the value of attribute edit_uri.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#title ⇒ Object
Returns the value of attribute title.
-
#updated ⇒ Object
Returns the value of attribute updated.
-
#uri ⇒ Object
Returns the value of attribute uri.
Class Method Summary collapse
- .build_xml(uri, edit_uri, author_name, title, content, draft, categories, updated) ⇒ Object
-
.create(uri: '', edit_uri: '', author_name: '', title: '', content: '', draft: 'no', categories: [], updated: '') {|entry| ... } ⇒ Hatenablog::Entry
Create a new blog entry from arguments.
-
.load_xml(xml) ⇒ Hatenablog::Entry
Create a new blog entry from a XML string.
Instance Method Summary collapse
Methods included from AfterHook
Instance Attribute Details
#author_name ⇒ Object
Returns the value of attribute author_name.
36 37 38 |
# File 'lib/hatenablog/entry.rb', line 36 def @author_name end |
#categories ⇒ Array
86 87 88 |
# File 'lib/hatenablog/entry.rb', line 86 def categories @categories.dup end |
#content ⇒ Object
Returns the value of attribute content.
36 37 38 |
# File 'lib/hatenablog/entry.rb', line 36 def content @content end |
#draft ⇒ Object
Returns the value of attribute draft.
36 37 38 |
# File 'lib/hatenablog/entry.rb', line 36 def draft @draft end |
#edit_uri ⇒ Object
Returns the value of attribute edit_uri.
39 40 41 |
# File 'lib/hatenablog/entry.rb', line 39 def edit_uri @edit_uri end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
39 40 41 |
# File 'lib/hatenablog/entry.rb', line 39 def id @id end |
#title ⇒ Object
Returns the value of attribute title.
36 37 38 |
# File 'lib/hatenablog/entry.rb', line 36 def title @title end |
#updated ⇒ Object
Returns the value of attribute updated.
39 40 41 |
# File 'lib/hatenablog/entry.rb', line 39 def updated @updated end |
#uri ⇒ Object
Returns the value of attribute uri.
36 37 38 |
# File 'lib/hatenablog/entry.rb', line 36 def uri @uri end |
Class Method Details
.build_xml(uri, edit_uri, author_name, title, content, draft, categories, updated) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/hatenablog/entry.rb', line 106 def self.build_xml(uri, edit_uri, , title, content, draft, categories, updated) builder = Nokogiri::XML::Builder.new(encoding: 'utf-8') do |xml| xml.entry('xmlns' => 'http://www.w3.org/2005/Atom', 'xmlns:app' => 'http://www.w3.org/2007/app') do xml.link(href: edit_uri, rel: 'edit') xml.link(href: uri, rel: 'alternate', type: 'text/html') xml. do xml.name end xml.title title xml.content(content, type: 'text/x-markdown') xml.updated updated unless updated.nil? || updated.empty? unless categories.nil? categories.each do |category| xml.category(term: category) end end xml['app'].control do xml['app'].draft draft end end end builder.to_xml end |
.create(uri: '', edit_uri: '', author_name: '', title: '', content: '', draft: 'no', categories: [], updated: '') {|entry| ... } ⇒ Hatenablog::Entry
Create a new blog entry from arguments.
72 73 74 75 76 77 78 |
# File 'lib/hatenablog/entry.rb', line 72 def self.create(uri: '', edit_uri: '', author_name: '', title: '', content: '', draft: 'no', categories: [], updated: '') entry = Hatenablog::Entry.new(self.build_xml(uri, edit_uri, , title, content, draft, categories, updated)) yield entry if block_given? entry end |
.load_xml(xml) ⇒ Hatenablog::Entry
Create a new blog entry from a XML string.
58 59 60 |
# File 'lib/hatenablog/entry.rb', line 58 def self.load_xml(xml) Hatenablog::Entry.new(xml) end |
Instance Method Details
#draft? ⇒ Boolean
81 82 83 |
# File 'lib/hatenablog/entry.rb', line 81 def draft? @draft == 'yes' end |
#each_category ⇒ Object
90 91 92 93 94 |
# File 'lib/hatenablog/entry.rb', line 90 def each_category @categories.each do |category| yield category end end |
#formatted_content ⇒ String
102 103 104 |
# File 'lib/hatenablog/entry.rb', line 102 def formatted_content @formatted_content end |
#to_xml ⇒ String
97 98 99 |
# File 'lib/hatenablog/entry.rb', line 97 def to_xml @document.to_s.gsub(/\"/, "'") end |