the right code flow in attached code? (ruby) -


In the script of my script code (see the first piece of code below) I have the array @post_csv_order To specify order and key => value relationship of elements for @ post [post_id] . I run all the values ​​(such as forum_id, post_chittel, etc.) and run an assignment line in @post [forum_id] = hash [* @ post_csv_order.flatten] . Why do I have to do this array? I should have all major names (= CSV header) and key => value definition in one place, so when I change the order or I add new extension that I want to store, I do not need to make any changes in code is. I should use that array approach, even if the object is to be used instead of hash.

To create an array of the second item of the array, @ post_csv_order should be otherwise defined otherwise I will be undefined local variable or method .

A little more about the whole script : It flows in that way - I parse a stage page and this gives me an array of posts. And get all the details I need to post and store it. I want to use the array @post_csv_order at this point, to make a new hash of these details. I want to use the array @post_csv_order to save all data I found in CSV and then to read that CSV the next time, when I run the script, I can update any field I am (like previous post author, date of last post, number of views). 'Pp' @ post = {} forum_id = 123 post_chirt = "test post" @ post_com_order = [["forum", forum_id], ["post title", post_ title]] @ post [forum_id] = hash [* postcase_order. Flaton] PP @ Post

So I thought I would define all the variables used in the array and empty the string forum_id, post_ title = "" but I'm not sure how to do this in Ruby's right way.

  Required 'PP' @ Post = {} Forums_id, Post_title = "" @Pastka CV_order = [[Forum ID ", Forum_ID], [" Title of post ", post_ title]] forum_id = 123 post_chitel = "test post" @ post [forum_id] = hash [* @ post_csv_order.flatten] pp @ Posted  

Can PS edit any suggestions or titles? Know how its name ...

I'm not completely clear what you 're again To do I am trying, but I think that you may have to face many of your challenges by using Post Objects, which includes a forum ID, post title, etc. Your import method will create a number of these items, which then

Edit

I think that "ruby-:

  @post_csv_order = [[forum '], method_ to_Get_Forum_Id_Or_Nil | | ""], ["Title of post", method_ To_Get_Post_Title_Or_Nil ||  

But I am still not clear what you are doing - is this method being in the continuation of the lines of CSV?

Edit 2 The problem with hashes is that they do not guarantee to keep the order, so you will need to confirm the order found. In the pseudo-code, it seems that you want to do the following:

  • Pars page -> Result in multiple forum entries
  • Move the forum entries and the appropriate order and Unique keys for future retrieval to save them
  • Reload the object at a later date, compare them with a new pass on the parsed forum, and if updated separately (and save)

I am afraid that I Paco is to convey back to using Skriyrekord and objects. It is possible to use a hash here, but it has actually made Ruby and Rails to do for you. For example, to do what you're doing above, all you have to do is (mostly the actual code):

p = post.new p.unique_key = create_unique_key (Forums_ID) p .forum_id = Forum_id.p.post_title = post_title p.save

and to get them later (mostly actual code):

  all_posts = post .feed (: all) all_posts.each do | Posted in | Update_if_changed (post, perced_post [post.unique_key]) expiration  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -