Class: Parchemin::Article
- Inherits:
-
Object
- Object
- Parchemin::Article
- Defined in:
- lib/parchemin/models/article.rb
Overview
This class represent an article
Constant Summary collapse
- MONTHS =
%w(janv fevr mars avr mai juin juill aout sept oct nov dec)
Instance Attribute Summary collapse
-
#abstract ⇒ Object
readonly
Returns the value of attribute abstract.
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#filename ⇒ Object
readonly
returns the expanded path of the article.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
-
.all(conditions = {}) ⇒ Object
returns all the available articles.
-
.search(search) ⇒ Object
a rudimentary search engine.
Instance Method Summary collapse
-
#<=>(article) ⇒ Object
defines the comparison of two articles.
-
#comments ⇒ Object
returns all the comments available for an article.
-
#date ⇒ Object
returns a well formatted date.
-
#day ⇒ Object
returns the day of the article’s creation date.
-
#initialize(id) ⇒ Article
constructor
initializes the article with its name.
-
#month ⇒ Object
returns the month of the article’s creation date.
-
#year ⇒ Object
returns the year of the article’s creation date.
Constructor Details
#initialize(id) ⇒ Article
initializes the article with its name
14 15 16 17 18 19 20 21 |
# File 'lib/parchemin/models/article.rb', line 14 def initialize(id) if id =~ /(.*)\.markdown$/ @id = $1 else @id = id end parse_attributes(filename) end |
Instance Attribute Details
#abstract ⇒ Object (readonly)
Returns the value of attribute abstract.
9 10 11 |
# File 'lib/parchemin/models/article.rb', line 9 def abstract @abstract end |
#body ⇒ Object (readonly)
Returns the value of attribute body.
9 10 11 |
# File 'lib/parchemin/models/article.rb', line 9 def body @body end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
9 10 11 |
# File 'lib/parchemin/models/article.rb', line 9 def created_at @created_at end |
#filename ⇒ Object (readonly)
returns the expanded path of the article
24 25 26 |
# File 'lib/parchemin/models/article.rb', line 24 def filename @filename end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/parchemin/models/article.rb', line 9 def id @id end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
9 10 11 |
# File 'lib/parchemin/models/article.rb', line 9 def @tags end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
9 10 11 |
# File 'lib/parchemin/models/article.rb', line 9 def title @title end |
Class Method Details
.all(conditions = {}) ⇒ Object
returns all the available articles. The articles starting by a ‘.’ are not loaded
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/parchemin/models/article.rb', line 54 def self.all(conditions={}) articles = [] Dir.foreach(Parchemin::Config.articles_path) do |entry| next if entry.match /^\./ article = Article.new(entry) if conditions.count == 0 articles << article else articles << article if not filtered?(article, conditions) end end articles.sort.reverse end |
.search(search) ⇒ Object
a rudimentary search engine
70 71 72 73 74 75 76 |
# File 'lib/parchemin/models/article.rb', line 70 def self.search(search) output = `grep -Hi '#{search}' #{Parchemin::Config.articles_path}/* | cut -d: -f1` articles = output.split("\n").uniq.map do |filename| Article.new(File.basename(filename)) end articles.sort.reverse end |
Instance Method Details
#<=>(article) ⇒ Object
defines the comparison of two articles
49 50 51 |
# File 'lib/parchemin/models/article.rb', line 49 def <=>(article) created_at <=> article.created_at end |
#comments ⇒ Object
returns all the comments available for an article
79 80 81 |
# File 'lib/parchemin/models/article.rb', line 79 def comments Comment.where(:article => @id) end |
#date ⇒ Object
returns a well formatted date
44 45 46 |
# File 'lib/parchemin/models/article.rb', line 44 def date "#{day} #{month.capitalize} #{year}" end |
#day ⇒ Object
returns the day of the article’s creation date
34 35 36 |
# File 'lib/parchemin/models/article.rb', line 34 def day @created_at.day end |
#month ⇒ Object
returns the month of the article’s creation date
29 30 31 |
# File 'lib/parchemin/models/article.rb', line 29 def month MONTHS[@created_at.month-1] end |
#year ⇒ Object
returns the year of the article’s creation date
39 40 41 |
# File 'lib/parchemin/models/article.rb', line 39 def year @created_at.year end |