class Capybara::BootstrapDatepicker::Picker
The Picker
class interacts with the datepicker
Public Class Methods
Source
# File lib/capybara-bootstrap-datepicker.rb, line 58 def initialize @element = find_picker end
Initializes the picker
Public Instance Methods
Source
# File lib/capybara-bootstrap-datepicker.rb, line 93 def find_day(value) day_xpath = <<-XPATH .//*[contains(concat(' ', @class, ' '), ' day ') and not(contains(concat(' ', @class, ' '), ' old ')) and not(contains(concat(' ', @class, ' '), ' new ')) and normalize-space(text())='#{value}'] XPATH days.find :xpath, day_xpath end
Get the day we want to click on @param value [Fixnum] the day of the desired date @return the DOM element to click on
Source
# File lib/capybara-bootstrap-datepicker.rb, line 86 def find_month(value) months.find ".month:nth-child(#{value})" 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
Source
# File lib/capybara-bootstrap-datepicker.rb, line 79 def find_year(value) years.find '.year', text: 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
Source
# File lib/capybara-bootstrap-datepicker.rb, line 63 def goto_decade_panel current_month.click if days.visible? current_year.click if months.visible? end
Reveals the decade panel
Private Instance Methods
Source
# File lib/capybara-bootstrap-datepicker.rb, line 180 def click_next_decade years.find('th.next').click end
Click and display next decade
Source
# File lib/capybara-bootstrap-datepicker.rb, line 175 def click_prev_decade years.find('th.prev').click end
Click and display previous decade
Source
# File lib/capybara-bootstrap-datepicker.rb, line 150 def current_decade find_switch :years end
Get the current decade panel @param (see find_switch
) @return (see find_switch
)
Source
# File lib/capybara-bootstrap-datepicker.rb, line 170 def current_decade_minmax current_decade.text.split('-').map(&:to_i) end
Get the current decade period @return [Array<Fixnum, Fixnum>] the min and max years of the decade
Source
# File lib/capybara-bootstrap-datepicker.rb, line 164 def current_month find_switch :days end
Get the current month panel @param (see find_switch
) @return (see find_switch
)
Source
# File lib/capybara-bootstrap-datepicker.rb, line 157 def current_year find_switch :months end
Get the current year panel @param (see find_switch
) @return (see find_switch
)
Source
# File lib/capybara-bootstrap-datepicker.rb, line 143 def days find_period :days end
Get the days panel @param (see find_period
) @return (see find_period
)
Source
# File lib/capybara-bootstrap-datepicker.rb, line 115 def find_period(period) @element.find(".datepicker-#{period}", visible: false) end
Get the datepicker panel @param period [:years, :months, :days] the panel’s period @return the DOM element of the panel
Source
# File lib/capybara-bootstrap-datepicker.rb, line 108 def find_picker Capybara.find(:xpath, '//body').find('.datepicker') end
Get the datepicker @return the DOM element of the datepicker
Source
# File lib/capybara-bootstrap-datepicker.rb, line 122 def find_switch(period) send(period).find('th.datepicker-switch', visible: false) end
Get the up level panel @param (see find_period
) @return the DOM element of the switch panel button
Source
# File lib/capybara-bootstrap-datepicker.rb, line 188 def gap(min, max) return 0 if min >= max ((max / 10) - (min / 10)) end
Calculates the distance in decades between min and max @param min [Fixnum] a 4 digits year @param max [Fixnum] a 4 digits year @return [Fixnum] the distance in decades between min and max
Source
# File lib/capybara-bootstrap-datepicker.rb, line 204 def goto_next_decade(decade_end, value) gap(decade_end, value).times { click_next_decade } 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
Source
# File lib/capybara-bootstrap-datepicker.rb, line 197 def goto_prev_decade(value, decade_start) gap(value, decade_start).times { click_prev_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
Source
# File lib/capybara-bootstrap-datepicker.rb, line 136 def months find_period :months end
Get the months panel @param (see find_period
) @return (see find_period
)
Source
# File lib/capybara-bootstrap-datepicker.rb, line 129 def years find_period :years end
Get the years panel @param (see find_period
) @return (see find_period
)