Class: Needish::Need

Inherits:
Object
  • Object
show all
Includes:
EasyClassMaker
Defined in:
lib/needish/need.rb

Class Method Summary collapse

Methods included from EasyClassMaker

included, #initialize

Class Method Details

.generic_from_xml(xml) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/needish/need.rb', line 40

def generic_from_xml(xml)
 
  result = []

  xml.search("needs").each do  |userNeeds|
    (userNeeds/:need).each do |need|
    Need.new do |u|
          u.id           =     need[:id] 
          u.created      =     need[:created]
          u.city         =     need[:city]
          u.timediff     =     need[:timediff]
          u.status       =     need[:status]
          
          (need/:subject).each do |subject|
          u.subject     =         subject.inner_html
        end
        (need/:text).each do |text|
        u.text     =         text.inner_html
      end
      result << u
     end
   end 
  end
  return result
end

.generic_view_from_xml(xml) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/needish/need.rb', line 67

def generic_view_from_xml(xml)
  result = []
  #:help_id, :help_created, :help_stars, :help_timediff,:help_text,
  # :help_user_id,:help_user_name,:help_user_nickname,:help_user_picture_url,:help_user_displayname,:help_user_text
  

  xml.search("need").each do  |need|
    
    Need.new do |u|
          u.id           =     need[:id] 
          u.created      =     need[:created]
          u.city         =     need[:city]
          u.timediff     =     need[:timediff]
          u.status       =     need[:status]
      
          (need/:subject).each do |subject|
          u.subject     =         subject.inner_html
        end
        
        u.text     =         need.search('text').first.inner_html
      
      
  
      
      result << u
   end 
  end
  return result[0]
end

.new_from_xml(xml) ⇒ Object

Creates a new user from a piece of xml



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/needish/need.rb', line 11

def new_from_xml(xml)
 
  result = []

  xml.search("userNeeds").each do  |userNeeds|
    (userNeeds/:need).each do |need|
    Need.new do |u|
          u.id           =     need[:id] 
          u.created      =     need[:created]
          u.city         =     need[:city]
          u.timediff     =     need[:timediff]
          u.status       =     need[:status]
          (need/:subject).each do |subject|
          u.subject     =         subject.inner_html
        end
        (need/:text).each do |text|
        u.text     =         text.inner_html
      end
      result << u
     end 
   end  
  end
  return result
end