Class: TwitterCldr::Transforms::Transformer
- Inherits:
-
Object
- Object
- TwitterCldr::Transforms::Transformer
- Defined in:
- lib/twitter_cldr/transforms/transformer.rb
Constant Summary collapse
- RULE_CLASSES =
[ CommentRule, VariableRule, Transforms::TransformRule, Filters::FilterRule, Conversions::ConversionRule, ]
Instance Attribute Summary collapse
-
#direction ⇒ Object
readonly
Returns the value of attribute direction.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
-
#transform_id ⇒ Object
readonly
Returns the value of attribute transform_id.
Class Method Summary collapse
Instance Method Summary collapse
- #backward_rule_set ⇒ Object
-
#bidirectional? ⇒ Boolean
all rules are either forward or bidirectional.
- #forward_rule_set ⇒ Object
-
#initialize(rules, direction, transform_id) ⇒ Transformer
constructor
A new instance of Transformer.
Constructor Details
#initialize(rules, direction, transform_id) ⇒ Transformer
Returns a new instance of Transformer.
151 152 153 154 155 |
# File 'lib/twitter_cldr/transforms/transformer.rb', line 151 def initialize(rules, direction, transform_id) @rules = rules @direction = direction @transform_id = transform_id end |
Instance Attribute Details
#direction ⇒ Object (readonly)
Returns the value of attribute direction.
149 150 151 |
# File 'lib/twitter_cldr/transforms/transformer.rb', line 149 def direction @direction end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
149 150 151 |
# File 'lib/twitter_cldr/transforms/transformer.rb', line 149 def rules @rules end |
#transform_id ⇒ Object (readonly)
Returns the value of attribute transform_id.
149 150 151 |
# File 'lib/twitter_cldr/transforms/transformer.rb', line 149 def transform_id @transform_id end |
Class Method Details
.each_transform ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/twitter_cldr/transforms/transformer.rb', line 41 def each_transform if block_given? TransformId.transform_id_map.each do |aliass, _| yield aliass end else to_enum(__method__) end end |
.exists?(transform_id_or_str) ⇒ Boolean
21 22 23 24 25 |
# File 'lib/twitter_cldr/transforms/transformer.rb', line 21 def exists?(transform_id_or_str) !!get(transform_id_or_str) rescue => e false end |
.get(transform_id_or_str) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/twitter_cldr/transforms/transformer.rb', line 27 def get(transform_id_or_str) id = parse_id(transform_id_or_str) if resource_exists?(id) load(id).forward_rule_set else reversed_id = id.reverse if resource_exists?(reversed_id) load(reversed_id).backward_rule_set end end end |
Instance Method Details
#backward_rule_set ⇒ Object
166 167 168 169 170 171 172 173 |
# File 'lib/twitter_cldr/transforms/transformer.rb', line 166 def backward_rule_set if bidirectional? @backward_rule_set ||= forward_rule_set.invert else raise NotInvertibleError, "cannot invert this #{self.class.name}" end end |
#bidirectional? ⇒ Boolean
all rules are either forward or bidirectional
158 159 160 |
# File 'lib/twitter_cldr/transforms/transformer.rb', line 158 def bidirectional? direction == :bidirectional end |