class Hipmost::Hipchat::RoomRepository

Attributes

name_index[RW]
rooms[RW]

Public Class Methods

load_from(path) click to toggle source
# File lib/hipmost/hipchat/room_repository.rb, line 13
def self.load_from(path)
  new(path).tap(&:load)
end
new(path) click to toggle source
# File lib/hipmost/hipchat/room_repository.rb, line 17
def initialize(path)
  @path  = Pathname.new(path).join("rooms.json")
  @rooms = {}
  @name_index = {}
end

Public Instance Methods

file_data() click to toggle source
# File lib/hipmost/hipchat/room_repository.rb, line 37
def file_data
  if File.exists? @path
    File.read(@path)
  else
    abort "./data does not exist; did you forget to specify a path to the data?"
  end
end
find_by_name(name) click to toggle source
# File lib/hipmost/hipchat/room_repository.rb, line 33
def find_by_name(name)
  self[name_index[name]]
end
load(data = file_data) click to toggle source
# File lib/hipmost/hipchat/room_repository.rb, line 23
def load(data = file_data)
  json = JSON.load(data)

  json.each do |room_obj|
    room = room_obj["Room"]
    @rooms[room["id"]] = Room.new(room)
    @name_index[room["name"]] = room["id"]
  end
end