Class: Twine::TwineDefinition
- Inherits:
-
Object
- Object
- Twine::TwineDefinition
- Defined in:
- lib/twine/twine_file.rb
Instance Attribute Summary collapse
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#reference ⇒ Object
Returns the value of attribute reference.
-
#reference_key ⇒ Object
Returns the value of attribute reference_key.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#translations ⇒ Object
readonly
Returns the value of attribute translations.
Instance Method Summary collapse
-
#initialize(key) ⇒ TwineDefinition
constructor
A new instance of TwineDefinition.
-
#matches_tags?(tags, include_untagged) ⇒ Boolean
- [‘tag1’, ‘tag2’], [‘~tag3’]
-
(tag1 OR tag2) AND (!tag3).
- #raw_comment ⇒ Object
- #translation_for_lang(lang) ⇒ Object
Constructor Details
#initialize(key) ⇒ TwineDefinition
Returns a new instance of TwineDefinition.
10 11 12 13 14 15 |
# File 'lib/twine/twine_file.rb', line 10 def initialize(key) @key = key @comment = nil @tags = nil @translations = {} end |
Instance Attribute Details
#comment ⇒ Object
Returns the value of attribute comment.
4 5 6 |
# File 'lib/twine/twine_file.rb', line 4 def comment @comment end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
3 4 5 |
# File 'lib/twine/twine_file.rb', line 3 def key @key end |
#reference ⇒ Object
Returns the value of attribute reference.
7 8 9 |
# File 'lib/twine/twine_file.rb', line 7 def reference @reference end |
#reference_key ⇒ Object
Returns the value of attribute reference_key.
8 9 10 |
# File 'lib/twine/twine_file.rb', line 8 def reference_key @reference_key end |
#tags ⇒ Object
Returns the value of attribute tags.
5 6 7 |
# File 'lib/twine/twine_file.rb', line 5 def @tags end |
#translations ⇒ Object (readonly)
Returns the value of attribute translations.
6 7 8 |
# File 'lib/twine/twine_file.rb', line 6 def translations @translations end |
Instance Method Details
#matches_tags?(tags, include_untagged) ⇒ Boolean
- [‘tag1’, ‘tag2’], [‘~tag3’]
-
(tag1 OR tag2) AND (!tag3)
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/twine/twine_file.rb', line 26 def (, include_untagged) if == nil || .empty? # The user did not specify any tags. Everything passes. return true elsif @tags == nil # This definition has no tags -> check reference (if any) return reference ? reference.(, include_untagged) : include_untagged elsif @tags.empty? return include_untagged else return .all? do |set| , = set.partition { |tag| tag[0] != '~' } .map! { |tag| tag[1..-1] } = (!.empty? && !( & @tags).empty?) = (!.empty? && ( & @tags).empty?) or end end return false end |
#raw_comment ⇒ Object
21 22 23 |
# File 'lib/twine/twine_file.rb', line 21 def raw_comment @comment end |
#translation_for_lang(lang) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/twine/twine_file.rb', line 46 def translation_for_lang(lang) translation = [lang].flatten.map { |l| @translations[l] }.compact.first translation = reference.translation_for_lang(lang) if translation.nil? && reference return translation end |