Module: DeepStruct

Defined in:
lib/deep_struct.rb,
lib/deep_struct/version.rb

Defined Under Namespace

Classes: Array, FileReader, Hash

Constant Summary collapse

VERSION =
"1.1.0"

Class Method Summary collapse

Class Method Details

.convert_element_if_possible(e) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/deep_struct.rb', line 13

def self.convert_element_if_possible(e)
  case e
  when ::Array then DeepStruct::Array.new(e)
  when ::Hash  then DeepStruct::Hash.new(e)
  else
    e
  end
end

.from_data(data) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/deep_struct.rb', line 4

def self.from_data(data)
  case data
  when ::Array then DeepStruct::Array.new(data)
  when ::Hash  then DeepStruct::Hash.new(data)
  else
    raise "Unrecognized data: #{data.inspect}"
  end
end

.from_file(path) ⇒ Object



22
23
24
# File 'lib/deep_struct.rb', line 22

def self.from_file(path)
  from_data(FileReader.new(path).data)
end