Module: Jekyll::RandomFilter
- Defined in:
- lib/jekyll-random.rb
Instance Method Summary collapse
- #random_date(x, start_date = false, end_date = false) ⇒ Object
- #random_date_ago(x, days_ago = 100) ⇒ Object
- #random_item(x, items) ⇒ Object
- #random_number(x, min = 0, max = 100, round = 0) ⇒ Object
Instance Method Details
#random_date(x, start_date = false, end_date = false) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/jekyll-random.rb', line 27 def random_date(x, start_date=false, end_date=false) start_date = start_date ? Time.parse(start_date) : (Time.now - 60*60*24*100) end_date = end_date ? Time.parse(end_date) : Time.now Time.at(random_number(x, start_date.to_i, end_date.to_i)) end |
#random_date_ago(x, days_ago = 100) ⇒ Object
34 35 36 |
# File 'lib/jekyll-random.rb', line 34 def random_date_ago(x, days_ago=100) Date.today.prev_day(random_number(x, 0, days_ago)) end |
#random_item(x, items) ⇒ Object
21 22 23 24 25 |
# File 'lib/jekyll-random.rb', line 21 def random_item(x, items) index = random_number(x, 0, items.size) items[index] end |
#random_number(x, min = 0, max = 100, round = 0) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/jekyll-random.rb', line 6 def random_number(x, min=0, max=100, round=0) value = ((x * x * Math::PI * Math::E * (max + 1) * (Math.sin(x) / Math.cos(x * x)) ) % (max + 1 - min)) + min value = value > max ? max : value value = value < min ? min : value if round != 0 value = (('%.' + round.to_s + 'f') % value) else value = value.to_i end value end |