Class: Rdomino::Document
Instance Method Summary
collapse
Methods included from DomObject
#empty?, #initialize, #method_missing, #obj
Methods included from DbDcDoc
#dxl, #dxl_to_file
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Rdomino::DomObject
Instance Method Details
#[](itemname) ⇒ Object
72
73
74
|
# File 'lib/rdomino/document.rb', line 72
def [](itemname)
Item.new(@obj.getfirstitem(itemname.to_s))
end
|
#copy_to_database(destination) ⇒ Object
76
77
78
|
# File 'lib/rdomino/document.rb', line 76
def copy_to_database(destination) Document.new( obj.CopyToDatabase(destination.obj) )
end
|
#create_empty_fields(fields) ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/rdomino/document.rb', line 86
def create_empty_fields(fields)
changed = 0
fields.each do |field|
unless @obj.hasItem(field)
@obj.replaceItemValue(field,'')
changed += 1
end
end
save if changed > 0
changed
end
|
#created ⇒ Object
7
8
9
|
# File 'lib/rdomino/document.rb', line 7
def created
DateTime.strptime(obj.created,'%Y/%m/%d %H:%M:%S')
end
|
#find_or_create_item(i) ⇒ Object
67
68
69
70
|
# File 'lib/rdomino/document.rb', line 67
def find_or_create_item(i)
replace i => '' unless obj.hasitem i.to_s
self.[](i)
end
|
28
29
30
|
# File 'lib/rdomino/document.rb', line 28
def form
getItemValue('Form')[0]
end
|
#g(item) ⇒ Object
24
25
26
|
# File 'lib/rdomino/document.rb', line 24
def g(item)
get(item)[0]
end
|
#get(item) ⇒ Object
19
20
21
22
|
# File 'lib/rdomino/document.rb', line 19
def get(item)
@obj.getItemValue(item.to_s)
end
|
#id ⇒ Object
102
103
104
|
# File 'lib/rdomino/document.rb', line 102
def id
obj.noteid
end
|
#items ⇒ Object
63
64
65
|
# File 'lib/rdomino/document.rb', line 63
def items
@obj.items.map{|i| Item.new(i)}
end
|
#move_to_database(destination) ⇒ Object
80
81
82
83
84
|
# File 'lib/rdomino/document.rb', line 80
def move_to_database(destination)
target = copy_to_database(destination)
obj.remove(true)
target
end
|
#pp(by_type = nil) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/rdomino/document.rb', line 48
def pp(by_type=nil)
if @obj
puts "\n#{self.getItemValue('Form')[0]}"
puts " %-22s %-32s" % ['id',id]
puts " %-22s %-32s" % ['unid',unid]
items = self.items.map{|i| [i.name,i.type,i.text]}.sort_by{|a| ( by_type ? a[1].to_s : "" )+a[0] }
items.each do |i|
puts " %-22s %-10s %-30s" % i
end
else
puts "empty!"
end
self
end
|
#replace(h) ⇒ Object
11
12
13
14
15
16
17
|
# File 'lib/rdomino/document.rb', line 11
def replace(h)
h.each do |item,value|
@obj.replaceItemValue(item.to_s,value)
end
self
end
|
#save(force = true, make_response = false) ⇒ Object
98
99
100
|
# File 'lib/rdomino/document.rb', line 98
def save( force=true, make_response=false )
@obj.save(force, make_response)
end
|
#unid ⇒ Object
106
107
108
|
# File 'lib/rdomino/document.rb', line 106
def unid
obj.universalid
end
|
#update_attributes(h) ⇒ Object
returns array of changed items
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/rdomino/document.rb', line 33
def update_attributes(h)
changed = []
h.each do |key,value|
unless g(key) == value
changed << "#{key}:#{ self.g(key) }->#{value}"
@obj.replaceItemValue(key.to_s, value)
end
end
unless changed.empty?
save
changed.join(', ')
end
end
|