lib/infoboxer/templates/set.rb in infoboxer-0.2.7 vs lib/infoboxer/templates/set.rb in infoboxer-0.2.8
- old
+ new
@@ -1,6 +1,7 @@
# encoding: utf-8
+
module Infoboxer
module Templates
# Base class for defining set of templates, used for some site/domain.
#
# Currently only can be plugged in via {MediaWiki::Traits.templates}.
@@ -18,11 +19,11 @@
define(&definitions) if definitions
end
# @private
def find(name)
- _, template = @templates.detect{|m, t| m === name.downcase}
+ _, template = @templates.detect { |m, _t| m === name.downcase }
template || Base
end
# @private
def define(&definitions)
@@ -41,19 +42,19 @@
# ```ruby
# template 'Age' do
# def from
# fetch_date('1', '2', '3')
# end
- #
+ #
# def to
# fetch_date('4', '5', '6') || Date.today
# end
- #
+ #
# def value
# (to - from).to_i / 365 # FIXME: obviously
# end
- #
+ #
# def text
# "#{value} years"
# end
# end
# ```
@@ -98,20 +99,20 @@
# call their (or their parents') {Tree::Node#text}.
#
# Expected to be used inside Set definition block.
def replace(*replacements)
case
- when replacements.count == 2 && replacements.all?{|r| r.is_a?(String)}
+ when replacements.count == 2 && replacements.all? { |r| r.is_a?(String) }
name, what = *replacements
setup_class(name, Replace) do
define_method(:replace) do
what
end
end
when replacements.count == 1 && replacements.first.is_a?(Hash)
- replacements.first.each do |name, what|
- replace(name, what)
+ replacements.first.each do |nm, rep|
+ replace(nm, rep)
end
else
fail(ArgumentError, "Can't call :replace with #{replacements.join(', ')}")
end
end
@@ -161,16 +162,16 @@
# @private
def setup_class(name, base_class, options = {}, &definition)
match = options.fetch(:match, name.downcase)
base = options.fetch(:base, base_class)
- base = self.find(base) if base.is_a?(String)
+ base = find(base) if base.is_a?(String)
- Class.new(base, &definition).tap{|cls|
+ Class.new(base, &definition).tap do |cls|
cls.template_name = name
cls.template_options = options
@templates.unshift [match, cls]
- }
+ end
end
end
end
end