class Capybara::BootstrapDatepicker::Picker
The Picker
class interacts with the datepicker
Public Class Methods
Initializes the picker
# File lib/capybara-bootstrap-datepicker.rb, line 61 def initialize @element = find_picker end
Public Instance Methods
Get the day we want to click on @param value [Fixnum] the day of the desired date @return the DOM element to click on
# File lib/capybara-bootstrap-datepicker.rb, line 96 def find_day(value) day_xpath = <<-eos .//*[contains(concat(' ', @class, ' '), ' day ') and not(contains(concat(' ', @class, ' '), ' old ')) and not(contains(concat(' ', @class, ' '), ' new ')) and normalize-space(text())='#{value}'] eos days.find :xpath, day_xpath end
Get the month we want to click on @param value [Fixnum] the month of the desired date @return the DOM element to click on
# File lib/capybara-bootstrap-datepicker.rb, line 89 def find_month(value) months.find ".month:nth-child(#{value})" end
Get the year we want to click on @param value [Fixnum] the year of the desired date @return the DOM element to click on
# File lib/capybara-bootstrap-datepicker.rb, line 82 def find_year(value) years.find '.year', text: value end
Reveals the decade panel
# File lib/capybara-bootstrap-datepicker.rb, line 66 def goto_decade_panel current_month.click if days.visible? current_year.click if months.visible? end
Private Instance Methods
Click and display next decade
# File lib/capybara-bootstrap-datepicker.rb, line 182 def click_next_decade years.find('th.next').click end
Click and display previous decade
# File lib/capybara-bootstrap-datepicker.rb, line 177 def click_prev_decade years.find('th.prev').click end
Get the current decade panel @param (see find_switch
) @return (see find_switch
)
# File lib/capybara-bootstrap-datepicker.rb, line 152 def current_decade find_switch :years end
Get the current decade period @return [Array<Fixnum, Fixnum>] the min and max years of the decade
# File lib/capybara-bootstrap-datepicker.rb, line 172 def current_decade_minmax current_decade.text.split('-').map(&:to_i) end
Get the current month panel @param (see find_switch
) @return (see find_switch
)
# File lib/capybara-bootstrap-datepicker.rb, line 166 def current_month find_switch :days end
Get the current year panel @param (see find_switch
) @return (see find_switch
)
# File lib/capybara-bootstrap-datepicker.rb, line 159 def current_year find_switch :months end
Get the days panel @param (see find_period
) @return (see find_period
)
# File lib/capybara-bootstrap-datepicker.rb, line 145 def days find_period :days end
Get the datepicker panel @param period [:years, :months, :days] the panel’s period @return the DOM element of the panel
# File lib/capybara-bootstrap-datepicker.rb, line 117 def find_period(period) @element.find(".datepicker-#{period}", visible: false) end
Get the datepicker @return the DOM element of the datepicker
# File lib/capybara-bootstrap-datepicker.rb, line 110 def find_picker Capybara.find(:xpath, '//body').find('.datepicker') end
Get the up level panel @param (see find_period
) @return the DOM element of the switch panel button
# File lib/capybara-bootstrap-datepicker.rb, line 124 def find_switch(period) send(period).find('th.datepicker-switch', visible: false) end
Calculates the distance in decades between min and max @return [Fixnum] the distance in decades between min and max
# File lib/capybara-bootstrap-datepicker.rb, line 188 def gap(min, max) return 0 if min >= max (max - min) / 10 end
Go forward to the wanted decade @param decade_end [Fixnum] the last year of a decade @param value [Fixnum] the year of the desired date
# File lib/capybara-bootstrap-datepicker.rb, line 203 def goto_next_decade(decade_end, value) gap(decade_end, value).times { click_next_decade } end
Go backward to the wanted decade @param value [Fixnum] the year of the desired date @param decade_start [Fixnum] the first year of a decade
# File lib/capybara-bootstrap-datepicker.rb, line 196 def goto_prev_decade(value, decade_start) gap(value, decade_start).times { click_prev_decade } end
Get the months panel @param (see find_period
) @return (see find_period
)
# File lib/capybara-bootstrap-datepicker.rb, line 138 def months find_period :months end
Get the years panel @param (see find_period
) @return (see find_period
)
# File lib/capybara-bootstrap-datepicker.rb, line 131 def years find_period :years end