class Terrestrial::Cli::Bootstrapper::Entry

Public Class Methods

from_hash(hash, index) click to toggle source
# File lib/terrestrial/cli/bootstrapper.rb, line 98
def self.from_hash(hash, index)
  string    = hash.fetch("string")
  occurence = Occurence.from_hash(hash, index)

  new(string, [occurence])
end
new(string, occurences = []) click to toggle source
# File lib/terrestrial/cli/bootstrapper.rb, line 85
def initialize(string, occurences = [])
  @string = string
  @occurences = occurences
end

Public Instance Methods

add_occurence(hash, index) click to toggle source
# File lib/terrestrial/cli/bootstrapper.rb, line 126
def add_occurence(hash, index)
  if hash.fetch("string") == self.string
    @occurences << Occurence.from_hash(hash, index)
  else
    raise "Add non-matching string '#{hash.fetch("string")}' as an occurence to #{self.inspect}"
  end
end
as_separate_occurences() click to toggle source
# File lib/terrestrial/cli/bootstrapper.rb, line 117
def as_separate_occurences
  occurences.map do |occurence|
    EntryOccurence.new(occurence).tap do |occ|
      occ.string     = self.string
      occ.identifier = self.identifier
    end
  end
end
formatted_string() click to toggle source
# File lib/terrestrial/cli/bootstrapper.rb, line 90
def formatted_string
  if occurences.any? {|occ| occ.language == :swift}
    VariableNormalizer.run(string, swift: true)
  else
    VariableNormalizer.run(string)
  end
end
identifier() click to toggle source
# File lib/terrestrial/cli/bootstrapper.rb, line 105
def identifier
  @identifier ||= IdGenerator.generate(formatted_string)
end
occurences() click to toggle source
# File lib/terrestrial/cli/bootstrapper.rb, line 113
def occurences
  @occurences
end
string() click to toggle source
# File lib/terrestrial/cli/bootstrapper.rb, line 109
def string
  @string
end