Class: Inform::Ephemeral::Object

Inherits:
Object
  • Object
show all
Includes:
Context, Inform::Events, Genealogical, Linkable, Modular, Prototypical, Taggable, StoryTeller::Builtins, StoryTeller::Daemons, StoryTeller::IO, StoryTeller::Publisher
Defined in:
lib/story_teller/world_tree.rb,
lib/story_teller/inform/ephemeral/tag.rb,
lib/story_teller/inform/ephemeral/object.rb

Overview

class Object rubocop: disable Metrics/ClassLength

Direct Known Subclasses

StoryTeller::Daemons::Entheogen

Constant Summary collapse

DefaultShortNameTemplate =
'(%<short_name>s)'.freeze

Constants included from Prototypical

Prototypical::AccessorMethodTemplate, Prototypical::LinkPattern, Prototypical::MISSING_PROPERTIES_MESSAGE, Prototypical::MethodBooleanOrBangPattern, Prototypical::MethodWriterPattern, Prototypical::MethodWriterTemplate, Prototypical::VariableTemplate, Prototypical::WriterMethodTemplate

Constants included from Inform::Events

Inform::Events::DEFAULT_ADD_EVENT_PARAMS, Inform::Events::REGISTRY, Inform::Events::THREADS_PER_PROCESSOR

Constants included from Context

Context::AttributeFieldReferenceTemplate, Context::AttributeSetterMethodTemplate

Constants included from StoryTeller::Daemons

StoryTeller::Daemons::DaemonExecutionElapsedMessage, StoryTeller::Daemons::DaemonScanElapsedMessage, StoryTeller::Daemons::RecordNotFoundPattern

Constants included from StoryTeller::Subscribers

StoryTeller::Subscribers::REGISTRY

Constants included from StoryTeller::IO

StoryTeller::IO::DefaultLineLength, StoryTeller::IO::ItemPaddingString, StoryTeller::IO::MinimumCellPadding, StoryTeller::IO::MinimumColumnPadding, StoryTeller::IO::MinimumLineLength

Constants included from StoryTeller::Builtins

StoryTeller::Builtins::MethodDefinitionPattern, StoryTeller::Builtins::MethodTerminationPattern, StoryTeller::Builtins::NOUN, StoryTeller::Builtins::PLURAL, StoryTeller::Builtins::PREPOSITION, StoryTeller::Builtins::VERB

Constants included from StoryTeller::Color

StoryTeller::Color::BackgroundColorCodes, StoryTeller::Color::ColorCodes, StoryTeller::Color::NearestColor, StoryTeller::Color::StyleCodes

Constants included from StoryTeller::Articles

StoryTeller::Articles::LowercaseASpaceString, StoryTeller::Articles::LowercaseSomeSpaceString, StoryTeller::Articles::LowercaseTheSpaceString

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Genealogical

#>, #all?, #any?, #branch, #child, #collect, #concat, #count, #delete_if, #each, #each_with_object, #find, #find_all, #having, #in?, #include?, #map, #notin?, #reject, #select, #sibling, #siblings, #within?

Methods included from Modular

#after_initialize, #apply_modules, #mod, #modules_semaphore, #nil_safe_modules, #reset_modules, #unmod

Methods included from Taggable

#nil_safe_tags, #tag_names, #tagged_with?, #tagged_with_all?, #tagged_with_any?, #tagged_with_none?

Methods included from TagHelpers

#attributes, #has, #has?, #hasany?, #hasnt, #hasnt?

Methods included from Prototypical

#&, #_assign, #_get, #_set, #accessor_and_writer, #attempt_resolution, #constant_for_link_value, #context_event, #declared_property?, #ensure_properties_attribute!, #instance_variables_map, #key_refers_to_link?, #method_missing, #object_for_link_value, #property_defined?, #property_key_for, #prototype, #resolve_link_property, #set_link_property, #string?, #|

Methods included from Inform::Events

#active?, active_objects, #add_event, available_processors, #contextualize, #delay, each, #elementally, #event, #events, #immediately, init_java_pool, init_java_pooled_executor, init_java_scheduled_executor, init_java_scheduler, init_pool, init_scheduled_executor, init_scheduler, #interrupt, object_events, pool, pooled_executor, possibilities, #register_callback, scheduled_executor, scheduler

Methods included from Context

each_attribute, get_value, set, setter_method

Methods included from StoryTeller::Daemons

#StartDaemon, #StartTimer, #StopDaemon, #StopTimer, #before_destroy, #daemonic?, #daemonize, daemons, ensure_inform_library, execute, execute_daemon, execute_each_turn, #ghost, #heart, #init_heart, #occasionally, #on?, refresh_or_remove, #rescan, scan_objects, #schedules, #spawn, start, stop

Methods included from StoryTeller::Publisher

#muted?, #publish, #publish_except, #publish_only, #publish_system_message, #subscribers

Methods included from StoryTeller::Subscribers

#explicit_subscribers, #subscribe, #subscribers, #unsubscribe, #unsubscribe_all

Methods included from StoryTeller::IO

#connections, #flush_io, #inform, #many_per_line, #new_line, #noop, #out, #output_stream, #preference_value, #preferred_line_length, #print, #println, #prompt, #read, #reset_prompt, #session, #spaces, #tidy_output

Methods included from StoryTeller::Builtins

#__quit, #__read, #__restart, #__restore, #__save, #__verify, #apply_instance_behavior!, #classification, #compass, #content, #current_word, #deadflag, #deadflag=, #dict_par1, #dictionary, #disrobe, #drop, #emote, #findobject, #getobject, #go, #inform_object_class, #inform_object_collection, #inform_object_fetch, #initial, #language_descriptors, #language_pronouns, #library_method?, #life?, #light_adjusted, #method_source, #nothing, #num_words, #number, #object_name_matches?, #objectloop, #ofclass, #pause, #provides?, #randomly, #react_after?, #react_before?, #remaining_words, #resembles_method?, #say, #score, #score=, #search, #sequel_model?, #special, #the_time, #the_time=, #things_score, #things_score=, #to_s, #topic, #visibility_ceiling=, #with, #workflags

Methods included from StoryTeller::Plurals

#apply_inflections, #plural?, #pluralize, #singular?, #singularize

Methods included from StoryTeller::Color

#background_color, #color, #nearest_color, #style, #un_background_color, #un_color, #un_style

Methods included from StoryTeller::Articles

#A, #Cthatorthose, #Ctheyreorthats, #The, #a, #cthatorthose, #ctheyreorthats, #defart, #indefart, #isorare, #itorthem, #thatorthose, #the

Constructor Details

#initialize(textual_name = nil, *args, &block) ⇒ Object

rubocop: disable Metrics/AbcSize rubocop: disable Metrics/MethodLength



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/story_teller/inform/ephemeral/object.rb', line 59

def initialize(textual_name = nil, *args, &block)
  super(*args)
  @name = textual_name || self.class.name
  @short_name = textual_name || format(
    DefaultShortNameTemplate, short_name: self.class.name)
  @display_name = textual_name
  @description = nil
  @adjectives = []
  @properties = {}
  @links = []
  @modules = []
  @tags = []
  @children = []
  @visited = []
  @created_at = @modified_at = Time.now
  index_words if respond_to?(:index_words)
  EphemeralObjects[self.identity] = self
  EphemeralObjects[@display_name.to_s] = self unless @display_name.nil?
  self.with(&block) unless block.nil?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Inform::Prototypical

Instance Attribute Details

#created_atObject

Returns the value of attribute created_at.



51
52
53
# File 'lib/story_teller/inform/ephemeral/object.rb', line 51

def created_at
  @created_at
end

#display_nameObject

Returns the value of attribute display_name.



51
52
53
# File 'lib/story_teller/inform/ephemeral/object.rb', line 51

def display_name
  @display_name
end

#inflibObject

Returns the value of attribute inflib.



51
52
53
# File 'lib/story_teller/inform/ephemeral/object.rb', line 51

def inflib
  @inflib
end

Returns the value of attribute links.



51
52
53
# File 'lib/story_teller/inform/ephemeral/object.rb', line 51

def links
  @links
end

#modified_atObject

Returns the value of attribute modified_at.



51
52
53
# File 'lib/story_teller/inform/ephemeral/object.rb', line 51

def modified_at
  @modified_at
end

#modulesObject

Returns the value of attribute modules.



51
52
53
# File 'lib/story_teller/inform/ephemeral/object.rb', line 51

def modules
  @modules
end

#propertiesObject Also known as: values

Returns the value of attribute properties.



51
52
53
# File 'lib/story_teller/inform/ephemeral/object.rb', line 51

def properties
  @properties
end

#short_nameObject

Returns the value of attribute short_name.



51
52
53
# File 'lib/story_teller/inform/ephemeral/object.rb', line 51

def short_name
  @short_name
end

#tagsObject

Returns the value of attribute tags.



265
266
267
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 265

def tags
  @tags ||= []
end

#visitedObject

Returns the value of attribute visited.



51
52
53
# File 'lib/story_teller/inform/ephemeral/object.rb', line 51

def visited
  @visited
end

Class Method Details

.[](id) ⇒ Object



99
100
101
102
103
104
# File 'lib/story_teller/inform/ephemeral/object.rb', line 99

def self.[](id)
  object = EphemeralObjects[id]
  return object if object.is_a?(self)

  all.find { |candidate| candidate.id == id || candidate.identity == id }
end

.allObject



90
91
92
# File 'lib/story_teller/inform/ephemeral/object.rb', line 90

def self.all
  EphemeralObjects.values.select { |object| object.is_a?(self) }.uniq
end

.clearObject



94
95
96
97
# File 'lib/story_teller/inform/ephemeral/object.rb', line 94

def self.clear
  EphemeralObjects.clear
  EphemeralObjectsChildren.clear if defined?(EphemeralObjectsChildren)
end

.fetch_or_create_by_name(name) ⇒ Object

rubocop: enable Metrics/AbcSize rubocop: enable Metrics/MethodLength



82
83
84
85
86
87
88
# File 'lib/story_teller/inform/ephemeral/object.rb', line 82

def self.fetch_or_create_by_name(name)
  key = name.to_s
  object = EphemeralObjects[key]
  return object if object.is_a?(self)

  new(key).tap { |created| EphemeralObjects[key] = created }
end

Instance Method Details

#<<(o) ⇒ Object



169
170
171
172
173
174
175
# File 'lib/story_teller/inform/ephemeral/object.rb', line 169

def <<(o)
  return if self == o
  return unless o.object?

  o.parent = self
  @children << o
end

#<=>(other) ⇒ Object



123
124
125
# File 'lib/story_teller/inform/ephemeral/object.rb', line 123

def <=>(other)
  self.name <=> other.name
end

#[](property) ⇒ Object



106
107
108
109
110
111
112
# File 'lib/story_teller/inform/ephemeral/object.rb', line 106

def [](property)
  return description if property == :description
  return name if property == :name
  return short_name if property == :short_name

  properties[property]
end

#_get_object(link_name) ⇒ Object



236
237
238
# File 'lib/story_teller/inform/ephemeral/object.rb', line 236

def _get_object(link_name)
  find_link(link_name)&.to
end

#_set_object(link_name, obj = nil) ⇒ Object

rubocop: enable Style/TrivialAccessors



232
233
234
# File 'lib/story_teller/inform/ephemeral/object.rb', line 232

def _set_object(link_name, obj = nil)
  link(link_name, obj).to
end

#ancestorsObject



201
202
203
# File 'lib/story_teller/inform/ephemeral/object.rb', line 201

def ancestors
  self.parent.nil? ? [] : self.parent.ancestors + [self.parent]
end

#children(o = nil, prop = :@children) ⇒ Object



186
187
188
189
190
191
# File 'lib/story_teller/inform/ephemeral/object.rb', line 186

def children(o = nil, prop = :@children)
  return @children if o.nil?
  return o.instance_variable_get(prop).length if o.instance_variable_defined?(prop)

  o.children.length
end

#descendantsObject



205
206
207
# File 'lib/story_teller/inform/ephemeral/object.rb', line 205

def descendants
  @children + @children.map(&:descendants).flatten
end

#description(description = nil) ⇒ Object Also known as: description=



150
151
152
153
154
# File 'lib/story_teller/inform/ephemeral/object.rb', line 150

def description(description = nil)
  return @description if description.nil?

  @description = description
end

#empty?Boolean

Returns:

  • (Boolean)


182
183
184
# File 'lib/story_teller/inform/ephemeral/object.rb', line 182

def empty?(...)
  self.children.empty?(...)
end


240
241
242
# File 'lib/story_teller/inform/ephemeral/object.rb', line 240

def find_link(link_name)
  links.find { |x| x.name == link_name }
end

#idObject



133
134
135
# File 'lib/story_teller/inform/ephemeral/object.rb', line 133

def id
  self.object_id
end

#initObject Also known as: safe_init



274
275
276
# File 'lib/story_teller/inform/ephemeral/object.rb', line 274

def init
  self
end


244
245
246
247
248
# File 'lib/story_teller/inform/ephemeral/object.rb', line 244

def link(link_name, obj = nil)
  link = Inform::System::Link.new(name: link_name, to: obj, from: self)
  links << link
  link
end

#linked?(link_name) ⇒ Boolean Also known as: _key?

Returns:

  • (Boolean)


250
251
252
# File 'lib/story_teller/inform/ephemeral/object.rb', line 250

def linked?(link_name)
  links.count { |x| x.name == link_name } > 0
end

#linksfrom(link_name = nil) ⇒ Object



266
267
268
269
270
271
272
# File 'lib/story_teller/inform/ephemeral/object.rb', line 266

def linksfrom(link_name = nil)
  if link_name.nil?
    links.select { |x| x.to == self }.map(&:from)
  else
    links.select { |x| x.name == link_name && x.to == self }.map(&:from)
  end
end

#linkto(link_name) ⇒ Object



262
263
264
# File 'lib/story_teller/inform/ephemeral/object.rb', line 262

def linkto(link_name)
  _get_object(link_name)
end

#list_togetherObject



197
198
199
# File 'lib/story_teller/inform/ephemeral/object.rb', line 197

def list_together
  linkto :list_together
end

#locationObject



193
194
195
# File 'lib/story_teller/inform/ephemeral/object.rb', line 193

def location
  self.parent
end

#name(*args) ⇒ Object



141
142
143
144
145
146
147
148
# File 'lib/story_teller/inform/ephemeral/object.rb', line 141

def name(*args)
  return args.first.object_name if args.first.respond_to?(:object_name)
  return @name if args.empty?

  @name = ([@name] | args).flatten.uniq
  index_words if respond_to?(:index_words)
  @name
end

#name_wordsObject



162
163
164
165
166
167
# File 'lib/story_teller/inform/ephemeral/object.rb', line 162

def name_words
  name_words = @name
  name_words = name_words.split(/[,\s]+/) if name_words.respond_to?(:split)
  name_words.join(', ') if name_words.respond_to?(:join)
  name_words
end

#object_nameObject



158
159
160
# File 'lib/story_teller/inform/ephemeral/object.rb', line 158

def object_name
  @display_name || @short_name || @name
end

#object_typeObject



137
138
139
# File 'lib/story_teller/inform/ephemeral/object.rb', line 137

def object_type
  self.class
end

#parent(o = nil, &block) ⇒ Object



213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/story_teller/inform/ephemeral/object.rb', line 213

def parent(o = nil, &block)
  return @parent if o.nil?

  o.safe_refresh if o.respond_to? :safe_refresh
  return unless o.respond_to? :parent

  obj_parent = block_given? ? parent_selector(o, &block) : o.parent
  return nil if obj_parent.nil?

  obj_parent.safe_refresh if obj_parent.respond_to? :safe_refresh
  obj_parent
end

#parent=(o) ⇒ Object

rubocop: disable Style/TrivialAccessors



227
228
229
# File 'lib/story_teller/inform/ephemeral/object.rb', line 227

def parent=(o)
  @parent = o
end

#parse(s) ⇒ Object



127
128
129
130
131
# File 'lib/story_teller/inform/ephemeral/object.rb', line 127

def parse(s)
  return if inflib.nil?

  inflib.semaphore.synchronize { inflib.parse(s) }
end

#refreshObject Also known as: safe_refresh



280
281
282
# File 'lib/story_teller/inform/ephemeral/object.rb', line 280

def refresh
  self
end

#removeObject



177
178
179
180
# File 'lib/story_teller/inform/ephemeral/object.rb', line 177

def remove
  @children.clear
  @parent = nil
end

#rootObject



209
210
211
# File 'lib/story_teller/inform/ephemeral/object.rb', line 209

def root
  self.parent.nil? ? self : self.parent.root
end

#save(*_args) ⇒ Object Also known as: safe_save



286
287
288
# File 'lib/story_teller/inform/ephemeral/object.rb', line 286

def save(*_args)
  self
end

#tag(*args) ⇒ Object



249
250
251
252
253
254
255
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 249

def tag(*args)
  workflags.add self.identity if args.delete :workflag
  tag_names(args).each do |tag|
    tags << tag.to_sym
  end
  self
end

#to_hashObject



114
115
116
117
118
119
120
121
# File 'lib/story_teller/inform/ephemeral/object.rb', line 114

def to_hash
  properties.merge(
    id: id,
    name: name,
    short_name: short_name,
    description: description
  )
end


256
257
258
# File 'lib/story_teller/inform/ephemeral/object.rb', line 256

def unlink(link_name)
  links.delete_at(links.index { |x| x.name == link_name })
end

#untag(*args) ⇒ Object



257
258
259
260
261
262
263
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 257

def untag(*args)
  workflags.delete self.identity if args.delete :workflag
  (nil_safe_tags & tag_names(args)).each do |tag|
    tags.delete tag
  end
  self
end