Class: Pebbles::VoyageConferenceRoom::Floor

Inherits:
Object
  • Object
show all
Defined in:
lib/pebbles/voyage_conference_room/floor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFloor

Returns a new instance of Floor.



6
7
8
9
10
11
# File 'lib/pebbles/voyage_conference_room/floor.rb', line 6

def initialize
  gem_spec   = Gem::Specification.find_by_name("pebbles-voyage_conference_room")
  rooms_spec = YAML.load_file("#{gem_spec.gem_dir}/config/rooms.yml")
  @floor_map = rooms_spec["floor_map"]
  @rooms     = rooms_spec["rooms"]
end

Instance Attribute Details

#floor_mapObject (readonly)

Returns the value of attribute floor_map.



12
13
14
# File 'lib/pebbles/voyage_conference_room/floor.rb', line 12

def floor_map
  @floor_map
end

#roomsObject (readonly)

Returns the value of attribute rooms.



12
13
14
# File 'lib/pebbles/voyage_conference_room/floor.rb', line 12

def rooms
  @rooms
end

Instance Method Details

#show_map(options) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/pebbles/voyage_conference_room/floor.rb', line 14

def show_map(options)
  name = options["name"].to_s.downcase
  code = options["code"]

  selected_rooms = rooms.select! do |k, v|
    k == name || v["aliases"].include?(name) || v["code"] == code
  end

  map = floor_map
  if options["with_code"]
    selected_rooms.map{ |k,v| v["code"] }.each{ |code| map.gsub!(code, "/".color(:red)) }
  else
    selected_rooms.map{ |k,v| v["code"] }.each{ |code| map.gsub!(code, '/') }
    map.gsub!(/[a-z]/, ' ')
    map.gsub!("/", "/".color(:red))
  end
  map
end