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

Constant Summary

Constants included from Logging

Logging::ForwardSlashPattern, Logging::RubyLogLevels

Instance Method Summary collapse

Methods included from Logging

config, #get_formatted_logger_name, #init_java_logger, #init_logger, #init_ruby_logger, #log, log_level, log_level=, #normalize_ruby_log_level, #ruby_log_formatter, #symbolize_numeric_log_level

Methods included from Inform::ObjectHelpers

#object?, #sysobj?

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



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

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

#blank?Boolean

Returns:

  • (Boolean)


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

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

#identityObject



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

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)


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

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)


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

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

#positive?Boolean

Returns:

  • (Boolean)


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

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