Class: Miyano::Site
- Inherits:
-
Object
- Object
- Miyano::Site
- Defined in:
- lib/miyano/site.rb
Instance Method Summary collapse
- #_tags ⇒ Object
- #add_post(post) ⇒ Object
- #current_tag ⇒ Object
- #current_tag=(tag) ⇒ Object
-
#initialize ⇒ Site
constructor
A new instance of Site.
- #posts ⇒ Object
- #tags ⇒ Object
Constructor Details
#initialize ⇒ Site
Returns a new instance of Site.
4 5 6 7 |
# File 'lib/miyano/site.rb', line 4 def initialize @posts = [] @tags = {} end |
Instance Method Details
#_tags ⇒ Object
29 30 31 |
# File 'lib/miyano/site.rb', line 29 def @tags end |
#add_post(post) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/miyano/site.rb', line 13 def add_post(post) @posts << post @posts.sort_by! {|p| [p.mod_date, p.cre_date]} @posts.reverse! post..each do |tag| if @tags.include? tag @tags[tag] += 1 else @tags[tag] = 1 end end @tags = @tags.sort_by {|key, value| [-value, key.length]} .to_h end |
#current_tag ⇒ Object
57 58 59 |
# File 'lib/miyano/site.rb', line 57 def current_tag @current_tag end |
#current_tag=(tag) ⇒ Object
61 62 63 |
# File 'lib/miyano/site.rb', line 61 def current_tag=(tag) @current_tag = tag end |
#posts ⇒ Object
9 10 11 |
# File 'lib/miyano/site.rb', line 9 def posts @posts end |
#tags ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/miyano/site.rb', line 33 def prefix = @current_tag = [] if prefix.nil? @tags.each do |_t, _| t = _t.split("/").first << t unless .include? t end return end @tags.each do |_t, _| next if _t.length <= prefix.length if _t.start_with? prefix t = _t.delete_prefix prefix t = t.delete_prefix! "/" t = t.split("/").first if t << t unless t.nil? or .include? t end end return end |