module Entity

Public Instance Methods

entity(data, ns=DefaultEntities) click to toggle source
# File lib/taxon/entity.rb, line 17
def entity(data, ns=DefaultEntities)
  to_entity_name entity_tests(ns).find{|i| ns.send(i, data)}
end
entity?(data, pred, ns=DefaultEntities) click to toggle source
# File lib/taxon/entity.rb, line 13
def entity?(data, pred, ns=DefaultEntities)
  Taxon::Guard.predicate?(ns, pred) ? ns.send(pred, data) : false
end
entity_format_methods(ns) click to toggle source
# File lib/taxon/entity.rb, line 25
def entity_format_methods(ns)
  ns.public_instance_methods.select{|m| m.to_s.end_with?("?")}
end
entity_tests(ns=DefaultEntities) click to toggle source
# File lib/taxon/entity.rb, line 21
def entity_tests(ns=DefaultEntities)
  entity_format_methods(ns).map{|m| m.intern}
end
to_entity_name(method_name) click to toggle source
# File lib/taxon/entity.rb, line 29
def to_entity_name(method_name)
  if (method_name.is_a?(Symbol) || method_name.is_a?(String))
    method_name.to_s.split("_").map{|i| to_entity_word(i)}.join
  end
end
to_entity_word(word) click to toggle source
# File lib/taxon/entity.rb, line 35
def to_entity_word(word)
  word.end_with?("?") ? word.gsub(/\?/, "").capitalize : word.capitalize
end