Class: KramdownRFC::ParameterSet
- Includes:
- Kramdown::Utils::Html
- Defined in:
- lib/kramdown-rfc/parameterset.rb
Instance Attribute Summary collapse
-
#f ⇒ Object
readonly
Returns the value of attribute f.
Instance Method Summary collapse
- #[](pn) ⇒ Object
- #arr(an, converthash = true, must_have_one = false, &block) ⇒ Object
- #attr(pn) ⇒ Object
- #attrs(*pns) ⇒ Object
- #ele(pn, attr = nil, defcontent = nil) ⇒ Object
- #escattr(str) ⇒ Object
- #has(pn) ⇒ Object
-
#initialize(y) ⇒ ParameterSet
constructor
A new instance of ParameterSet.
- #rest ⇒ Object
-
#van(pn) ⇒ Object
pn is a parameter name, possibly with an =alias.
- #warn_if_leftovers ⇒ Object
Constructor Details
#initialize(y) ⇒ ParameterSet
Returns a new instance of ParameterSet.
7 8 9 10 |
# File 'lib/kramdown-rfc/parameterset.rb', line 7 def initialize(y) raise "*** invalid parameter set #{y.inspect}" unless Hash === y @f = y end |
Instance Attribute Details
#f ⇒ Object (readonly)
Returns the value of attribute f.
6 7 8 |
# File 'lib/kramdown-rfc/parameterset.rb', line 6 def f @f end |
Instance Method Details
#[](pn) ⇒ Object
11 12 13 |
# File 'lib/kramdown-rfc/parameterset.rb', line 11 def [](pn) @f.delete(pn.to_s) end |
#arr(an, converthash = true, must_have_one = false, &block) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/kramdown-rfc/parameterset.rb', line 39 def arr(an, converthash=true, must_have_one=false, &block) arr = self[an] || [] arr = [arr] if Hash === arr && converthash arr << { } if must_have_one && arr.empty? Array(arr).each(&block) end |
#attr(pn) ⇒ Object
25 26 27 28 |
# File 'lib/kramdown-rfc/parameterset.rb', line 25 def attr(pn) val, an = van(pn) %{#{an}="#{escattr(val)}"} if val end |
#attrs(*pns) ⇒ Object
29 30 31 |
# File 'lib/kramdown-rfc/parameterset.rb', line 29 def attrs(*pns) pns.map{ |pn| attr(pn) }.compact.join(" ") end |
#ele(pn, attr = nil, defcontent = nil) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/kramdown-rfc/parameterset.rb', line 32 def ele(pn, attr=nil, defcontent=nil) val, an = van(pn) val ||= defcontent Array(val).map do |val1| %{<#{[an, *Array(attr).map(&:to_s)].join(" ").strip}>#{escape_html(val1.to_s.strip)}</#{an}>} end.join(" ") end |
#escattr(str) ⇒ Object
17 18 19 |
# File 'lib/kramdown-rfc/parameterset.rb', line 17 def escattr(str) escape_html(str.to_s, :attribute) end |
#has(pn) ⇒ Object
14 15 16 |
# File 'lib/kramdown-rfc/parameterset.rb', line 14 def has(pn) @f[pn.to_s] end |
#rest ⇒ Object
45 46 47 |
# File 'lib/kramdown-rfc/parameterset.rb', line 45 def rest @f end |
#van(pn) ⇒ Object
pn is a parameter name, possibly with an =alias
20 21 22 23 24 |
# File 'lib/kramdown-rfc/parameterset.rb', line 20 def van(pn) # pn is a parameter name, possibly with an =alias an, pn = pn.to_s.split("=") pn ||= an [self[pn] || self[an], an] end |
#warn_if_leftovers ⇒ Object
48 49 50 51 52 |
# File 'lib/kramdown-rfc/parameterset.rb', line 48 def warn_if_leftovers if !@f.empty? warn "*** attributes left #{@f.inspect}!" end end |