Class: I18nContextGenerator::AndroidResource::Index
- Inherits:
-
Object
- Object
- I18nContextGenerator::AndroidResource::Index
- Defined in:
- lib/i18n_context_generator/android_resource.rb
Overview
Query object shared by parsers and diff/location consumers.
Instance Attribute Summary collapse
-
#entry_spans ⇒ Object
readonly
Returns the value of attribute entry_spans.
-
#resource_spans ⇒ Object
readonly
Returns the value of attribute resource_spans.
Instance Method Summary collapse
- #base_key_at(line_number) ⇒ Object
-
#initialize(entry_spans:, resource_spans:) ⇒ Index
constructor
A new instance of Index.
- #member_at(line_number, parent:) ⇒ Object
- #span_for(key) ⇒ Object
Constructor Details
#initialize(entry_spans:, resource_spans:) ⇒ Index
Returns a new instance of Index.
33 34 35 36 37 |
# File 'lib/i18n_context_generator/android_resource.rb', line 33 def initialize(entry_spans:, resource_spans:) @entry_spans = entry_spans.freeze @resource_spans = resource_spans.freeze @entries_by_key = @entry_spans.group_by(&:key) end |
Instance Attribute Details
#entry_spans ⇒ Object (readonly)
Returns the value of attribute entry_spans.
31 32 33 |
# File 'lib/i18n_context_generator/android_resource.rb', line 31 def entry_spans @entry_spans end |
#resource_spans ⇒ Object (readonly)
Returns the value of attribute resource_spans.
31 32 33 |
# File 'lib/i18n_context_generator/android_resource.rb', line 31 def resource_spans @resource_spans end |
Instance Method Details
#base_key_at(line_number) ⇒ Object
43 44 45 |
# File 'lib/i18n_context_generator/android_resource.rb', line 43 def base_key_at(line_number) @resource_spans.find { |span| span.cover?(line_number) }&.base_key end |
#member_at(line_number, parent:) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/i18n_context_generator/android_resource.rb', line 47 def member_at(line_number, parent:) matches = @entry_spans.select do |span| span.base_key == parent && span.resource_type != :string && span.cover?(line_number) end keys = matches.map(&:key).uniq keys.one? ? keys.first : nil end |
#span_for(key) ⇒ Object
39 40 41 |
# File 'lib/i18n_context_generator/android_resource.rb', line 39 def span_for(key) @entries_by_key[key]&.first end |