{"action":"created","issue":{"url":"https://api.github.com/repos/ManageIQ/manageiq/issues/5774","labels_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/5774/labels{/name}","comments_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/5774/comments","events_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/5774/events","html_url":"https://github.com/ManageIQ/manageiq/pull/5774","id":121324987,"number":5774,"title":"Reduce code duplication connected with TREND_LIMIT_PERCENTS","user":{"login":"DNNX","id":447953,"avatar_url":"https://avatars.githubusercontent.com/u/447953?v=3","gravatar_id":"","url":"https://api.github.com/users/DNNX","html_url":"https://github.com/DNNX","followers_url":"https://api.github.com/users/DNNX/followers","following_url":"https://api.github.com/users/DNNX/following{/other_user}","gists_url":"https://api.github.com/users/DNNX/gists{/gist_id}","starred_url":"https://api.github.com/users/DNNX/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DNNX/subscriptions","organizations_url":"https://api.github.com/users/DNNX/orgs","repos_url":"https://api.github.com/users/DNNX/repos","events_url":"https://api.github.com/users/DNNX/events{/privacy}","received_events_url":"https://api.github.com/users/DNNX/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-12-09T19:53:26Z","updated_at":"2015-12-09T20:03:41Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/ManageIQ/manageiq/pulls/5774","html_url":"https://github.com/ManageIQ/manageiq/pull/5774","diff_url":"https://github.com/ManageIQ/manageiq/pull/5774.diff","patch_url":"https://github.com/ManageIQ/manageiq/pull/5774.patch"},"body":"It should work faster now as well.\r\n\r\nThe new hash is not fully equivalent to the previous `TREND_LIMIT_PERCENTS.invert.sort_by(&:last).reverse`, because the `TREND_LIMIT_....reverse` expression returns an array of pairs (i.e. `[[\"200%\", 200], [\"190%\", 190] ...`), and the new hash I introduced in this commit is a hash, but for the use case we're interested in (`options_for_select`) it doesn't matter since `options_for_select` transforms input hash to array of pairs. [link](http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/options_for_select)\r\n\r\nOne thing I could do as well is make hash construction method a bit smarter.\r\n\r\nLike this:\r\n\r\n```ruby\r\n  TREND_LIMIT_PERCENTS = \r\n    (200.step(100, -10).to_a + 95.downto(50, -5).to_a).map { |x| [\"#{x}%\", x] }\r\n```\r\n\r\nor like this:\r\n```ruby\r\n  TREND_LIMIT_PERCENTS = %w[\r\n    200\r\n    190\r\n    180\r\n    170\r\n    160\r\n    150\r\n    140\r\n    130\r\n    120\r\n    110\r\n    100\r\n    95\r\n    90\r\n    85\r\n    80\r\n    75\r\n    70\r\n    65\r\n    60\r\n    55\r\n    50\r\n  ].map { |x| [\"#{x}%\", x.to_i] }\r\n```\r\n\r\nBut I decided not to go this road because I'm not sure that it is more readable. Let me know if I should replace the original hash literal with one of the code snippets above though."},"comment":{"url":"https://api.github.com/repos/ManageIQ/manageiq/issues/comments/163374344","html_url":"https://github.com/ManageIQ/manageiq/pull/5774#issuecomment-163374344","issue_url":"https://api.github.com/repos/ManageIQ/manageiq/issues/5774","id":163374344,"user":{"login":"miq-bot","id":7806257,"avatar_url":"https://avatars.githubusercontent.com/u/7806257?v=3","gravatar_id":"","url":"https://api.github.com/users/miq-bot","html_url":"https://github.com/miq-bot","followers_url":"https://api.github.com/users/miq-bot/followers","following_url":"https://api.github.com/users/miq-bot/following{/other_user}","gists_url":"https://api.github.com/users/miq-bot/gists{/gist_id}","starred_url":"https://api.github.com/users/miq-bot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/miq-bot/subscriptions","organizations_url":"https://api.github.com/users/miq-bot/orgs","repos_url":"https://api.github.com/users/miq-bot/repos","events_url":"https://api.github.com/users/miq-bot/events{/privacy}","received_events_url":"https://api.github.com/users/miq-bot/received_events","type":"User","site_admin":false},"created_at":"2015-12-09T20:03:41Z","updated_at":"2015-12-09T20:03:41Z","body":"<rubocop />Checked commit https://github.com/DNNX/manageiq/commit/793326450507352d3538a0abbb89484be304f9c6 with ruby 2.2.3, rubocop 0.34.2, and haml-lint 0.13.0\n2 files checked, 10 offenses detected\n\n**app/helpers/ui_constants.rb**\n- [ ] :large_orange_diamond: - [Line 369](https://github.com/DNNX/manageiq/blob/793326450507352d3538a0abbb89484be304f9c6/app/helpers/ui_constants.rb#L369), Col 5 - [Style/AlignHash](http://rubydoc.info/gems/rubocop/0.34.2/RuboCop/Cop/Style/AlignHash) - Align the elements of a hash literal if they span more than one line.\n- [ ] :large_orange_diamond: - [Line 370](https://github.com/DNNX/manageiq/blob/793326450507352d3538a0abbb89484be304f9c6/app/helpers/ui_constants.rb#L370), Col 5 - [Style/AlignHash](http://rubydoc.info/gems/rubocop/0.34.2/RuboCop/Cop/Style/AlignHash) - Align the elements of a hash literal if they span more than one line.\n- [ ] :large_orange_diamond: - [Line 371](https://github.com/DNNX/manageiq/blob/793326450507352d3538a0abbb89484be304f9c6/app/helpers/ui_constants.rb#L371), Col 5 - [Style/AlignHash](http://rubydoc.info/gems/rubocop/0.34.2/RuboCop/Cop/Style/AlignHash) - Align the elements of a hash literal if they span more than one line.\n- [ ] :large_orange_diamond: - [Line 372](https://github.com/DNNX/manageiq/blob/793326450507352d3538a0abbb89484be304f9c6/app/helpers/ui_constants.rb#L372), Col 5 - [Style/AlignHash](http://rubydoc.info/gems/rubocop/0.34.2/RuboCop/Cop/Style/AlignHash) - Align the elements of a hash literal if they span more than one line.\n- [ ] :large_orange_diamond: - [Line 373](https://github.com/DNNX/manageiq/blob/793326450507352d3538a0abbb89484be304f9c6/app/helpers/ui_constants.rb#L373), Col 5 - [Style/AlignHash](http://rubydoc.info/gems/rubocop/0.34.2/RuboCop/Cop/Style/AlignHash) - Align the elements of a hash literal if they span more than one line.\n- [ ] :large_orange_diamond: - [Line 374](https://github.com/DNNX/manageiq/blob/793326450507352d3538a0abbb89484be304f9c6/app/helpers/ui_constants.rb#L374), Col 5 - [Style/AlignHash](http://rubydoc.info/gems/rubocop/0.34.2/RuboCop/Cop/Style/AlignHash) - Align the elements of a hash literal if they span more than one line.\n- [ ] :large_orange_diamond: - [Line 375](https://github.com/DNNX/manageiq/blob/793326450507352d3538a0abbb89484be304f9c6/app/helpers/ui_constants.rb#L375), Col 5 - [Style/AlignHash](http://rubydoc.info/gems/rubocop/0.34.2/RuboCop/Cop/Style/AlignHash) - Align the elements of a hash literal if they span more than one line.\n- [ ] :large_orange_diamond: - [Line 376](https://github.com/DNNX/manageiq/blob/793326450507352d3538a0abbb89484be304f9c6/app/helpers/ui_constants.rb#L376), Col 5 - [Style/AlignHash](http://rubydoc.info/gems/rubocop/0.34.2/RuboCop/Cop/Style/AlignHash) - Align the elements of a hash literal if they span more than one line.\n- [ ] :large_orange_diamond: - [Line 377](https://github.com/DNNX/manageiq/blob/793326450507352d3538a0abbb89484be304f9c6/app/helpers/ui_constants.rb#L377), Col 5 - [Style/AlignHash](http://rubydoc.info/gems/rubocop/0.34.2/RuboCop/Cop/Style/AlignHash) - Align the elements of a hash literal if they span more than one line.\n- [ ] :large_orange_diamond: - [Line 378](https://github.com/DNNX/manageiq/blob/793326450507352d3538a0abbb89484be304f9c6/app/helpers/ui_constants.rb#L378), Col 5 - [Style/AlignHash](http://rubydoc.info/gems/rubocop/0.34.2/RuboCop/Cop/Style/AlignHash) - Align the elements of a hash literal if they span more than one line.\n"}}