Class: QiitaExport::Article
- Inherits:
-
Object
- Object
- QiitaExport::Article
- Defined in:
- lib/qiita-export/article.rb
Constant Summary collapse
- HTML_TEMPLATE =
<<-"EOS" <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title><%= @title %></title> </head> <body> <h1><%= @title %></h1> <%= @rendered_body %> </body> </html> EOS
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#images ⇒ Object
readonly
Returns the value of attribute images.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#raw_body ⇒ Object
readonly
Returns the value of attribute raw_body.
-
#rendered_body ⇒ Object
readonly
Returns the value of attribute rendered_body.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#updated_at ⇒ Object
readonly
Returns the value of attribute updated_at.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#user_id ⇒ Object
readonly
Returns the value of attribute user_id.
Instance Method Summary collapse
-
#initialize(key, url, title, raw_body, rendered_body, created_at, updated_at, user_id) ⇒ Article
constructor
A new instance of Article.
- #save ⇒ Object
Constructor Details
#initialize(key, url, title, raw_body, rendered_body, created_at, updated_at, user_id) ⇒ Article
Returns a new instance of Article.
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/qiita-export/article.rb', line 23 def initialize(key, url, title, raw_body, rendered_body, created_at, updated_at, user_id) @key = key @url = url @title = title @raw_body = raw_body @rendered_body = rendered_body @created_at = created_at @updated_at = updated_at @user_id = user_id @images = Image.extract_urls(@key, @raw_body) end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
6 7 8 |
# File 'lib/qiita-export/article.rb', line 6 def created_at @created_at end |
#images ⇒ Object (readonly)
Returns the value of attribute images.
6 7 8 |
# File 'lib/qiita-export/article.rb', line 6 def images @images end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
6 7 8 |
# File 'lib/qiita-export/article.rb', line 6 def key @key end |
#raw_body ⇒ Object (readonly)
Returns the value of attribute raw_body.
6 7 8 |
# File 'lib/qiita-export/article.rb', line 6 def raw_body @raw_body end |
#rendered_body ⇒ Object (readonly)
Returns the value of attribute rendered_body.
6 7 8 |
# File 'lib/qiita-export/article.rb', line 6 def rendered_body @rendered_body end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
6 7 8 |
# File 'lib/qiita-export/article.rb', line 6 def title @title end |
#updated_at ⇒ Object (readonly)
Returns the value of attribute updated_at.
6 7 8 |
# File 'lib/qiita-export/article.rb', line 6 def updated_at @updated_at end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
6 7 8 |
# File 'lib/qiita-export/article.rb', line 6 def url @url end |
#user_id ⇒ Object (readonly)
Returns the value of attribute user_id.
6 7 8 |
# File 'lib/qiita-export/article.rb', line 6 def user_id @user_id end |
Instance Method Details
#save ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/qiita-export/article.rb', line 35 def save save_dir = File.join(Config.export_dir_path, Config.team_name(@url), @key) FileUtils.makedirs(save_dir) unless Dir.exists?(save_dir) file_path = File.join(save_dir, Config.filename(title)) File.open(file_path, "w") { |f| f.write export_content } if (Config.image_export?) @images.each { |image| image.save(save_dir) } end end |