Module: RIO::Ext::YAML::Input

Defined in:
lib/rio/ext/yaml.rb

Instance Method Summary collapse

Instance Method Details

#apto_(arg) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/rio/ext/yaml.rb', line 75

def apto_(arg)
  case arg
  when ::Array,::String then super
  when ::IO,::StringIO then cpto_io_(arg)
  else super
  end
end

#cpto_(arg) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'lib/rio/ext/yaml.rb', line 66

def cpto_(arg)
  #p callstr('cpto_',arg.inspect)
  
  case arg
  when ::Array,::String then super
  when ::IO,::StringIO then cpto_io_(arg)
  else super
  end
end

#cpto_io_(ioarg) ⇒ Object



82
83
84
85
86
87
88
89
# File 'lib/rio/ext/yaml.rb', line 82

def cpto_io_(ioarg)
  recs = self.to_a
  if recs.size == 1
    YAML.dump(recs[0],ioarg)
  else
    YAML.dump(recs,ioarg)
  end
end

#cpto_string_(string) ⇒ Object



90
91
92
# File 'lib/rio/ext/yaml.rb', line 90

def cpto_string_(string)
  string << ::YAML.dump_stream(self.contents)
end

#each_rec_(&block) ⇒ Object



101
102
103
104
105
106
107
108
109
# File 'lib/rio/ext/yaml.rb', line 101

def each_rec_(&block)
  case cx['stream_itertype']
  when 'lines' then super
  when 'records' then ::YAML.load_documents(self.ioh,&block)
  when 'rows' then ::YAML.load_documents(self.ioh) { |obj| yield obj.to_yaml }
  else ::YAML.load_documents(self.ioh,&block)
  end
  self
end

#get_(arg = nil) ⇒ Object



93
94
95
96
97
98
99
100
# File 'lib/rio/ext/yaml.rb', line 93

def get_(arg=nil)
  case cx['stream_itertype']
  when 'lines' then super
  when 'records' then ::YAML.load(self.ioh)
  when 'rows' then ::YAML.dump(::YAML.load(self.ioh))
  else ::YAML.load(self.ioh)
  end
end

#getobjObject



113
114
115
# File 'lib/rio/ext/yaml.rb', line 113

def getobj()
  getrec()
end

#loadObject



110
111
112
# File 'lib/rio/ext/yaml.rb', line 110

def load()
  getrec()
end