class Twine::TwineDefinition

Attributes

comment[RW]
key[R]
reference[RW]
reference_key[RW]
tags[RW]
translations[R]

Public Class Methods

new(key) click to toggle source
# File lib/twine/twine_file.rb, line 10
def initialize(key)
  @key = key
  @comment = nil
  @tags = nil
  @translations = {}
end

Public Instance Methods

matches_tags?(tags, include_untagged) click to toggle source
['tag1', 'tag2'], ['~tag3']

(tag1 OR tag2) AND (!tag3)

# File lib/twine/twine_file.rb, line 26
def matches_tags?(tags, include_untagged)
  if tags == nil || tags.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.matches_tags?(tags, include_untagged) : include_untagged
  elsif @tags.empty?
    return include_untagged
  else
    return tags.all? do |set|
      regular_tags, negated_tags = set.partition { |tag| tag[0] != '~' }
      negated_tags.map! { |tag| tag[1..-1] }
      matches_regular_tags = (!regular_tags.empty? && !(regular_tags & @tags).empty?)
      matches_negated_tags = (!negated_tags.empty? && (negated_tags & @tags).empty?)
      matches_regular_tags or matches_negated_tags
    end
  end

  return false
end
raw_comment() click to toggle source
# File lib/twine/twine_file.rb, line 21
def raw_comment
  @comment
end
translation_for_lang(lang) click to toggle source
# File lib/twine/twine_file.rb, line 46
def translation_for_lang(lang)
  translation = [lang].flatten.map { |l| @translations[l] }.first

  translation = reference.translation_for_lang(lang) if translation.nil? && reference

  return translation
end