Class: I18nliner::Scope
- Inherits:
-
Object
- Object
- I18nliner::Scope
- Defined in:
- lib/i18nliner/scope.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#allow_relative ⇒ Object
(also: #allow_relative?)
readonly
Returns the value of attribute allow_relative.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#remove_whitespace ⇒ Object
(also: #remove_whitespace?)
Returns the value of attribute remove_whitespace.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(scope = nil, options = {}) ⇒ Scope
constructor
A new instance of Scope.
- #normalize_key(key, inferred, i18n_scope) ⇒ Object
- #root? ⇒ Boolean
Constructor Details
#initialize(scope = nil, options = {}) ⇒ Scope
Returns a new instance of Scope.
10 11 12 13 14 15 |
# File 'lib/i18nliner/scope.rb', line 10 def initialize(scope = nil, = {}) @scope = scope ? "#{scope}." : scope @allow_relative = .fetch(:allow_relative, false) @remove_whitespace = .fetch(:remove_whitespace, false) @context = .fetch(:context, nil) end |
Instance Attribute Details
#allow_relative ⇒ Object (readonly) Also known as: allow_relative?
Returns the value of attribute allow_relative.
4 5 6 |
# File 'lib/i18nliner/scope.rb', line 4 def allow_relative @allow_relative end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
5 6 7 |
# File 'lib/i18nliner/scope.rb', line 5 def context @context end |
#remove_whitespace ⇒ Object Also known as: remove_whitespace?
Returns the value of attribute remove_whitespace.
7 8 9 |
# File 'lib/i18nliner/scope.rb', line 7 def remove_whitespace @remove_whitespace end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
3 4 5 |
# File 'lib/i18nliner/scope.rb', line 3 def scope @scope end |
Class Method Details
.root ⇒ Object
31 32 33 |
# File 'lib/i18nliner/scope.rb', line 31 def self.root @root ||= new end |
Instance Method Details
#normalize_key(key, inferred, i18n_scope) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/i18nliner/scope.rb', line 17 def normalize_key(key, inferred, i18n_scope) return key if key.nil? if key.is_a?(Array) return key.map { |k| normalize_key(k, inferred, i18n_scope) } end key = key.to_s.dup if allow_relative? && key.sub!(/\A\./, '') scope + key else key end end |
#root? ⇒ Boolean
35 36 37 |
# File 'lib/i18nliner/scope.rb', line 35 def root? scope.blank? end |