Class: Lich::Gemstone::Messaging

Inherits:
Object
  • Object
show all
Defined in:
documented/gemstone/creature.rb

Overview

Represents the messaging associated with a creature.

Constant Summary collapse

PLACEHOLDER_MAP =
{
  Pronoun: %w[He Her His It She],
  pronoun: %w[he her his it she],
  direction: %w[north south east west up down northeast northwest southeast southwest],
  weapon: %w[RAW:.+?]
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Messaging

Returns a new instance of Messaging.



650
651
652
653
654
# File 'documented/gemstone/creature.rb', line 650

def initialize(data)
  data.each do |key, value|
    instance_variable_set("@#{key}", normalize(value))
  end
end

Instance Attribute Details

#arrivalObject

Returns the value of attribute arrival.



639
640
641
# File 'documented/gemstone/creature.rb', line 639

def arrival
  @arrival
end

#attackObject

Returns the value of attribute attack.



639
640
641
# File 'documented/gemstone/creature.rb', line 639

def attack
  @attack
end

#biteObject

Returns the value of attribute bite.



639
640
641
# File 'documented/gemstone/creature.rb', line 639

def bite
  @bite
end

#clawObject

Returns the value of attribute claw.



639
640
641
# File 'documented/gemstone/creature.rb', line 639

def claw
  @claw
end

#deathObject

Returns the value of attribute death.



639
640
641
# File 'documented/gemstone/creature.rb', line 639

def death
  @death
end

#descriptionObject

Returns the value of attribute description.



639
640
641
# File 'documented/gemstone/creature.rb', line 639

def description
  @description
end

#enrageObject

Returns the value of attribute enrage.



639
640
641
# File 'documented/gemstone/creature.rb', line 639

def enrage
  @enrage
end

#fleeObject

Returns the value of attribute flee.



639
640
641
# File 'documented/gemstone/creature.rb', line 639

def flee
  @flee
end

#frenzyObject

Returns the value of attribute frenzy.



639
640
641
# File 'documented/gemstone/creature.rb', line 639

def frenzy
  @frenzy
end

#mstrikeObject

Returns the value of attribute mstrike.



639
640
641
# File 'documented/gemstone/creature.rb', line 639

def mstrike
  @mstrike
end

#spell_prepObject

Returns the value of attribute spell_prep.



639
640
641
# File 'documented/gemstone/creature.rb', line 639

def spell_prep
  @spell_prep
end

#sympathyObject

Returns the value of attribute sympathy.



639
640
641
# File 'documented/gemstone/creature.rb', line 639

def sympathy
  @sympathy
end

Instance Method Details

#display(field, subs = {}) ⇒ Object



668
669
670
671
672
673
674
675
676
677
# File 'documented/gemstone/creature.rb', line 668

def display(field, subs = {})
  msg = send(field)
  if msg.is_a?(Array)
    msg.map { |m| m.is_a?(PlaceholderTemplate) ? m.to_display(subs) : m }.join("\n")
  elsif msg.is_a?(PlaceholderTemplate)
    msg.to_display(subs)
  else
    msg
  end
end

#match(field, str) ⇒ Object



679
680
681
682
683
684
685
686
# File 'documented/gemstone/creature.rb', line 679

def match(field, str)
  msg = send(field)
  if msg.is_a?(PlaceholderTemplate)
    msg.match(str)
  else
    msg == str ? {} : nil
  end
end

#normalize(value) ⇒ Object



656
657
658
659
660
661
662
663
664
665
666
# File 'documented/gemstone/creature.rb', line 656

def normalize(value)
  if value.is_a?(Array)
    value.map { |v| normalize(v) }
  elsif value.is_a?(String) && value.match?(/\{[a-zA-Z_]+\}/)
    phs = value.scan(/\{([a-zA-Z_]+)\}/).flatten.map(&:to_sym)
    placeholders = phs.map { |ph| [ph, PLACEHOLDER_MAP[ph] || []] }.to_h
    PlaceholderTemplate.new(value, placeholders)
  else
    value
  end
end