Class: Object

Inherits:
BasicObject
Includes:
Inform::Matchers, Inform::ObjectHelpers, Inform::SetHelpers, Logging
Defined in:
lib/story_teller/mixins.rb,
lib/story_teller/helpers.rb,
lib/story_teller/helpers.rb

Overview

Define some built-in Inform helper methods

Instance Method Summary collapse

Methods included from Logging

#log, log_level, log_level=

Methods included from Inform::ObjectHelpers

#ephemeral?, #object?

Methods included from Inform::Matchers

#matches?, #matches_any_exactly?, #matches_exactly?, #matches_last_exactly?

Methods included from Inform::SetHelpers

#in?, #notin?

Instance Method Details

#+(other) ⇒ Object



31
32
33
# File 'lib/story_teller/mixins.rb', line 31

def +(other)
  format(JoinedTemplate, str: self.to_s, other: other.to_s)
end

#blank?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/story_teller/mixins.rb', line 60

def blank?
  respond_to?(:empty?) ? empty? : self.nil?
end

#identityObject



35
36
37
38
39
40
41
42
# File 'lib/story_teller/mixins.rb', line 35

def identity
  identification = { klass: self.class }
  identifier = (self.respond_to?(:object?) && self.object? ? self.id : self.object_id) || 0
  identification[:name] = (self.respond_to?(:name) ? self.name : nil) || 'unnamed'
  identification[:hex] = identifier << 1
  identification[:id] = identifier
  format(ObjectIdentityTemplate, identification)
end

#negative?Boolean

Returns:

  • (Boolean)


54
55
56
57
58
# File 'lib/story_teller/mixins.rb', line 54

def negative?
  # TODO: This might be as simple as:
  # self.to_i.negative?
  self.to_s.match?(/\A-?\d+?(\.\d+)?\Z/)
end

#number?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/story_teller/mixins.rb', line 44

def number?
  self.to_s.match?(/\A[+-]?\d+?(\.\d+)?\Z/)
end

#positive?Boolean

Returns:

  • (Boolean)


48
49
50
51
52
# File 'lib/story_teller/mixins.rb', line 48

def positive?
  # TODO: This might be as simple as:
  # self.to_i.positive?
  self.to_s.match?(/\A+?\d+?(\.\d+)?\Z/)
end