Search code examples
ruby-on-railsrubyruby-on-rails-3rubygemsgarb-gem

How to get particular data from the Openstruct


I am using garb gem to fetch the data from the google analytics and I getting the data in Openstruct format and I am struggling to parse it and get the desired values out.

#<OpenStruct visits="142640", percent_new_visits="100.0", visitor_type="New Visitor">

I googled but did not find anything relevant to this. I am newbie to ruby on rails ENV.

Kindly help me out


Solution

  • You just call method on args like

    object.visits
    object.percent_new_visits
    object.visitor_type
    

    See the document about OpenStruct on Ruby doc http://ruby-doc.org/stdlib-1.9.3/libdoc/ostruct/rdoc/index.html