Class: HatenablogPublisher::Context
- Inherits:
-
Object
- Object
- HatenablogPublisher::Context
- Defined in:
- lib/hatenablog_publisher/context.rb
Instance Attribute Summary collapse
-
#categories ⇒ Object
readonly
Returns the value of attribute categories.
-
#hatena ⇒ Object
readonly
Returns the value of attribute hatena.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#updated ⇒ Object
readonly
Returns the value of attribute updated.
Instance Method Summary collapse
- #add_entry_context(entry) ⇒ Object
- #add_image_context(image, tag) ⇒ Object
- #image_syntax(tag) ⇒ Object
-
#initialize(io) ⇒ Context
constructor
A new instance of Context.
- #metadata ⇒ Object
- #posted_image?(tag) ⇒ Boolean
- #reload_context ⇒ Object
- #time_to_s(str) ⇒ Object
Constructor Details
#initialize(io) ⇒ Context
Returns a new instance of Context.
11 12 13 14 15 |
# File 'lib/hatenablog_publisher/context.rb', line 11 def initialize(io) @io = io read_context end |
Instance Attribute Details
#categories ⇒ Object (readonly)
Returns the value of attribute categories.
9 10 11 |
# File 'lib/hatenablog_publisher/context.rb', line 9 def categories @categories end |
#hatena ⇒ Object (readonly)
Returns the value of attribute hatena.
9 10 11 |
# File 'lib/hatenablog_publisher/context.rb', line 9 def hatena @hatena end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
9 10 11 |
# File 'lib/hatenablog_publisher/context.rb', line 9 def text @text end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
9 10 11 |
# File 'lib/hatenablog_publisher/context.rb', line 9 def title @title end |
#updated ⇒ Object (readonly)
Returns the value of attribute updated.
9 10 11 |
# File 'lib/hatenablog_publisher/context.rb', line 9 def updated @updated end |
Instance Method Details
#add_entry_context(entry) ⇒ Object
43 44 45 46 47 |
# File 'lib/hatenablog_publisher/context.rb', line 43 def add_entry_context(entry) @hatena ||= {} @hatena[:id] = entry['id'].first.split('-').last @updated = time_to_s(entry['updated'].first) end |
#add_image_context(image, tag) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/hatenablog_publisher/context.rb', line 22 def add_image_context(image, tag) # APIのレスポンスをそのまま使用すると記事上でフォトライフへのリンクになってしまうため、管理画面から画像投稿した結果と合わせた(image -> plain) syntax = "[#{image['syntax'].first}]".gsub(/:image\]/,':plain]') @hatena ||= {} @hatena[:image] ||= {} @hatena[:image][tag.to_sym] = { syntax: syntax, id: image['id'].first, image_url: image['imageurl'].first } end |
#image_syntax(tag) ⇒ Object
35 36 37 |
# File 'lib/hatenablog_publisher/context.rb', line 35 def image_syntax(tag) @hatena.dig(:image, tag.to_sym, :syntax) end |
#metadata ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/hatenablog_publisher/context.rb', line 53 def { title: @title, category: @categories, updated: @updated, hatena: @hatena } end |
#posted_image?(tag) ⇒ Boolean
39 40 41 |
# File 'lib/hatenablog_publisher/context.rb', line 39 def posted_image?(tag) image_syntax(tag).present? end |
#reload_context ⇒ Object
17 18 19 20 |
# File 'lib/hatenablog_publisher/context.rb', line 17 def reload_context write_context read_context end |
#time_to_s(str) ⇒ Object
49 50 51 |
# File 'lib/hatenablog_publisher/context.rb', line 49 def time_to_s(str) Time.parse(str).strftime('%Y-%m-%dT%H:%M:%S') end |