Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/scraper #1

Merged
merged 40 commits into from
Dec 22, 2014
Merged

Feature/scraper #1

merged 40 commits into from
Dec 22, 2014

Conversation

mraaroncruz
Copy link
Contributor

Scraper works

@@ -0,0 +1,8 @@
# A sample Gemfile
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove :-)

@DominikGuzei
Copy link
Contributor

looks good to me 👍 although I am not too experienced with all of this so Clemens should also go over it

@award_title = get_award_title
@country = get_country
@description = get_description
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems somewhat redundant, especially @award = won?, because won? already assigns this instance variable.

I'd suggest renaming methods like get_title to title, let them cache their result in the respective instance variable and make them public. This way you also don't need the attr_readers.

Then your parse method could look like this:

def parse
  %i(title year organization details_link category award_won award_title country description).each(method(:public_send))
end

This way you could also choose to calculate all attributes in advance – by calling parse – or to lazy evaluate the attributes – by just calling the getters when you need them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this. But i did something earlier with Array.zip to do a to_json type of thing.

After using go, I am much more likely to do the title instead of get_title because it is obvious. So you're right, more memoized method that grab the value on first access would be reasonable. I will make that change.

The thing with won? is that i wanted a won? method. I guess I am in a phase where I don't like to do anything surprising... this really doesn't make any sense. I used to always do this. Maybe working with other languages can make your better language weird too. I can talk about this in India...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed this in latest commit 1b2721a

I just removed parse instead of your suggestion above

@mraaroncruz
Copy link
Contributor Author

I made updates based on @clemenshelm feedback.

def [](_) "" end
def text() "" end
def method_missing(*_) NullElement.new end
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty sweet! One little remark about quotes: Do we choose option B from the style guide? https://github.com/bbatsov/ruby-style-guide#consistent-string-literals

Would be really ok for me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generally use single quotes because I heard once that it is faster because it doesn't need to try to worry about string interpolation. As you can see, it isn't a standard of mine but I will be more consistent in the future, choosing single over double unless interpolation is happening.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

http://stackoverflow.com/questions/1836467/is-there-a-performance-gain-in-using-single-quotes-vs-double-quotes-in-ruby

The speed advantage is very little. But I'm good with every convention. So do you wanna go for option A or option B?

@clemenshelm
Copy link
Contributor

🐨 Awesome! Looking really good now!

if details && (slides = @details.at_css(".slides_container"))
slides.css('img').to_a
.compact
.map { |img| "%s%s" % [@base_url, img['src']]}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this how you usually write method chains?

I usually prefer to write it like

slides
  .css('img').to_a
  .compact
  .map { |img| "%s%s" % [@base_url, img['src']] }

Which style do you like better?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, and there's a space missing before the closing curly brace.

@mraaroncruz
Copy link
Contributor Author

Ok, let's merge this bitch

@mraaroncruz
Copy link
Contributor Author

ok? @clemenshelm

@clemenshelm
Copy link
Contributor

I can't. Can you merge the master and resolve the conflicts?

if you haven't bundled
`bundle install`
then
`ruby spec/all.rb`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's still the old spec file mentioned.

@mraaroncruz
Copy link
Contributor Author

yes

@mraaroncruz mraaroncruz merged commit 658848c into master Dec 22, 2014
@mraaroncruz mraaroncruz deleted the feature/scraper branch December 22, 2014 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants