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.
157 158 159 160 161 |
# File 'lib/twitter_cldr/transforms/transformer.rb', line 157 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.
155 156 157 |
# File 'lib/twitter_cldr/transforms/transformer.rb', line 155 def direction @direction end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
155 156 157 |
# File 'lib/twitter_cldr/transforms/transformer.rb', line 155 def rules @rules end |
#transform_id ⇒ Object (readonly)
Returns the value of attribute transform_id.
155 156 157 |
# File 'lib/twitter_cldr/transforms/transformer.rb', line 155 def transform_id @transform_id end |
Class Method Details
.each_transform ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/twitter_cldr/transforms/transformer.rb', line 41 def each_transform if block_given? path = TwitterCldr.resources.absolute_resource_path( File.join('shared', 'transforms') ) Dir.glob(File.join(path, '*.*')).each do |file| file = File.basename(file.chomp(File.extname(file))) source, target, variant = TransformId.split(file) yield TransformId.join(source, target, variant) 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 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
177 178 179 180 181 182 183 184 |
# File 'lib/twitter_cldr/transforms/transformer.rb', line 177 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
164 165 166 |
# File 'lib/twitter_cldr/transforms/transformer.rb', line 164 def bidirectional? direction == :bidirectional end |