Class: Jekyll::KargWare::LoremIpsum::ParserParameter
- Inherits:
-
Object
- Object
- Jekyll::KargWare::LoremIpsum::ParserParameter
- Defined in:
- lib/jekyll-kw-loremipsum/parser_parameter.rb
Overview
Parameters for parser class
Instance Attribute Summary collapse
-
#maxw ⇒ Object
readonly
Returns the value of attribute maxw.
-
#minw ⇒ Object
readonly
Returns the value of attribute minw.
-
#paras ⇒ Object
readonly
Returns the value of attribute paras.
-
#random ⇒ Object
readonly
Returns the value of attribute random.
-
#words ⇒ Object
readonly
Returns the value of attribute words.
Instance Method Summary collapse
- #init(parameters = nil) ⇒ Object
-
#initialize ⇒ ParserParameter
constructor
A new instance of ParserParameter.
- #to_s ⇒ Object
- #to_str_random ⇒ Object
- #use_paragraphs ⇒ Object
- #use_words ⇒ Object
Constructor Details
#initialize ⇒ ParserParameter
Returns a new instance of ParserParameter.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/jekyll-kw-loremipsum/parser_parameter.rb', line 10 def initialize super # 1w == 1 word (default 40) @words = 40 # 3p == 3 paragraphs (default 1) # 7miw == 7 Min words in para (default 40) # 15maw == 15 Max words in para (default 40) @paras = 1 @minw = 40 @maxw = 40 # random == Should the words be random (or ordered) (default false) @random = false end |
Instance Attribute Details
#maxw ⇒ Object (readonly)
Returns the value of attribute maxw.
8 9 10 |
# File 'lib/jekyll-kw-loremipsum/parser_parameter.rb', line 8 def maxw @maxw end |
#minw ⇒ Object (readonly)
Returns the value of attribute minw.
8 9 10 |
# File 'lib/jekyll-kw-loremipsum/parser_parameter.rb', line 8 def minw @minw end |
#paras ⇒ Object (readonly)
Returns the value of attribute paras.
8 9 10 |
# File 'lib/jekyll-kw-loremipsum/parser_parameter.rb', line 8 def paras @paras end |
#random ⇒ Object (readonly)
Returns the value of attribute random.
8 9 10 |
# File 'lib/jekyll-kw-loremipsum/parser_parameter.rb', line 8 def random @random end |
#words ⇒ Object (readonly)
Returns the value of attribute words.
8 9 10 |
# File 'lib/jekyll-kw-loremipsum/parser_parameter.rb', line 8 def words @words end |
Instance Method Details
#init(parameters = nil) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/jekyll-kw-loremipsum/parser_parameter.rb', line 25 def init(parameters = nil) return if parameters.nil? # TODO: Min > Max --> Warning # TODO: unkown words, e.g. "p, word, min, max" --> Warning matched_words = parameters.strip.match(/\d+w/) matched_paras = parameters.strip.match(/\d+p/) matched_minw = parameters.strip.match(/\d+miw/) matched_maxw = parameters.strip.match(/\d+maw/) matched_random = parameters.strip.match(/random/) # puts "Parser: W: %s P: %s MiW: %s MaW: %s Random: $s" % [matched_words, matched_paras, matched_minw, matched_maxw, matched_random] @words = matched_words[0].strip.sub('w', '').to_i if matched_words @paras = matched_paras[0].strip.sub('p', '').to_i if matched_paras @minw = matched_minw[0].strip.sub('miw', '').to_i if matched_minw @maxw = matched_maxw[0].strip.sub('maw', '').to_i if matched_maxw @random = true if matched_random end |
#to_s ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/jekyll-kw-loremipsum/parser_parameter.rb', line 58 def to_s if use_words format( 'W: %<amount_words>04d (%<random_or_sorted>s)', amount_words: @words, random_or_sorted: to_str_random ) else format( 'P: %<amount_paragraphs>04d (%<random_or_sorted>s) MiW: %<min_per_paragraph>04d MaW: %<max_per_paragraph>04d', amount_paragraphs: @paras, random_or_sorted: to_str_random, min_per_paragraph: @minw, max_per_paragraph: @maxw ) end end |
#to_str_random ⇒ Object
46 47 48 |
# File 'lib/jekyll-kw-loremipsum/parser_parameter.rb', line 46 def to_str_random @random ? 'random' : 'sorted' end |
#use_paragraphs ⇒ Object
54 55 56 |
# File 'lib/jekyll-kw-loremipsum/parser_parameter.rb', line 54 def use_paragraphs !use_words end |
#use_words ⇒ Object
50 51 52 |
# File 'lib/jekyll-kw-loremipsum/parser_parameter.rb', line 50 def use_words @paras.nil? || @paras == 1 end |