Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8770919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:39:26+00:00 2026-06-13T17:39:26+00:00

I have 30k+ documents in my database with this structure: { …, hours :

  • 0

I have 30k+ documents in my database with this structure:

{
  ...,
  "hours" : {
    "holiday" : {
      "New Years" : "Call",
      "Easter" : "Closed",
      "Memorial Day" : "Standard",
      "Independence Day" : "Standard",
      "Labor Day" : "Standard",
      "Thanksgiving" : "Closed",
      "Day After Thanksgiving" : "Call",
      "Christmas Eve" : "Call",
      "Christmas" : "Closed",
      "New Years Eve" : "Call"
    },
    "standard" : {
      "mon" : [{
        "open" : "8:00 am",
        "close" : "11:00 pm"
      }],
      "tue" : [{
        "open" : "8:00 am",
        "close" : "11:00 pm"
      }],
      "wed" : [{
        "open" : "8:00 am",
        "close" : "11:00 pm"
      }],
      "thu" : [{
        "open" : "8:00 am",
        "close" : "11:00 pm"
      }],
      "fri" : [{
        "open" : "8:00 am",
        "close" : "11:00 pm"
      }],
      "sat" : [{
        "open" : "8:00 am",
        "close" : "11:00 pm"
      }],
      "sun" : [{
        "open" : "8:00 am",
        "close" : "10:00 pm"
      }]
    }
  },
  ...
}

I am doing a complete rewrite from a php-driven site. I have been racking my brain and absolutely cannot come up with a way to make a form field that will allow me to set business.hours[“standard”][“mon”] properly. The site offers multiple open/close entries per day, for businesses that close for lunch, etc. That attribute would be set to [{“open” : “8:00 am”, “close” : “12:00 pm},{“open” : “1:00 pm”, “close” : “5:00 pm}] in such a case. I would like to offer two select boxes for each entry, one for open time and one for close time.

Here is my Model. including some getters/setters that I was attempting to figure out how to tie into my form…unsuccessfully.

class Business
  include Mongoid::Document
  include Mongoid::Timestamps
  field :ad, type: String
  field :address, type: String
  field :city, type: String
  field :claimed, type: Boolean
  field :coupons, type: String
  field :created_at, type: DateTime
  field :extra_services, type: Array
  field :hours, type: Hash
  field :name, type: String
  field :organization, type: String
  field :permanently_closed, type: Boolean, :default => false
  field :phone, type: String
  field :state, type: String
  field :tags, type: Array
  field :unit, type: String
  field :updated_at, type: DateTime
  field :website, type: String
  field :zip, type: String

  attr_accessible :ad, :address, :city, :claimed, :coupons, :created_at, :updated_at, :extra_services, :hours,
                  :name, :organization, :permanently_closed, :phone, :state, :tags, :unit, :website, :zip

  index({address: 1, unit: 1, city: 1, state: 1, zip: 1, organization: 1}, {unique: true, name: "address_unique_index"})

  after_initialize do |b|
    b.hours = Hash.new unless b.hours
    b.hours["holiday_hours"] = {"New Years" => "Call",
                                "Easter" => "Call",
                                "Memorial Day" => "Call",
                                "Independence Day" => "Call",
                                "Labor Day" => "Call",
                                "Thanksgiving" => "Call",
                                "Day After Thanksgiving" => "Call",
                                "Christmas Eve" => "Call",
                                "Christmas" => "Call",
                                "New Years Eve" => "Call"} unless b.hours["holiday_hours"]

    b.hours["standard_hours"] = Hash.new unless b.hours["standard_hours"]
  end

  def holiday_hours
    hours["holiday_hours"] if hours["holiday_hours"]
  end

  def holiday_hours=(hours)
    self.hours["holiday_hours"] = hours if hours.present?
  end

  def holiday_hours_for(holiday)
    hours["holiday_hours"][holiday.to_s] if hours["holiday_hours"][holiday.to_s]
  end

  def update_holiday_hours_for(holiday, hours_text)
    self.hours = Hash.new unless hours
    self.hours["holiday_hours"] = Hash.new unless hours["holiday_hours"]
    self.hours["holiday_hours"][holiday.to_s] = hours_text.to_s
  end

  def standard_hours
    hours["standard_hours"] if hours["standard_hours"]
  end

  def standard_hours_for(day)
    hours["standard_hours"][day.to_s] if hours["standard_hours"][day.to_s]
  end
end

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T17:39:27+00:00Added an answer on June 13, 2026 at 5:39 pm

    I figured out a way to do it, although I am not 100% sure that it is the right way.

    attr_accessible :ad, :address, :city, :claimed, :coupons, :created_at, :updated_at, :extra_services, :hours,
                    :name, :organization, :permanently_closed, :phone, :state, :tags, :unit, :website, :zip,
                    :hours_mon_open, :hours_mon_close, :hours_tue_open, :hours_tue_close, :hours_wed_open,
                    :hours_wed_close, :hours_thu_open, :hours_thu_close, :hours_fri_open, :hours_fri_close,
                    :hours_sat_open, :hours_sat_close, :hours_sun_open, :hours_sun_close
    
    attr_accessor :hours_mon_open, :hours_mon_close, :hours_tue_open, :hours_tue_close, :hours_wed_open,
                  :hours_wed_close, :hours_thu_open, :hours_thu_close, :hours_fri_open, :hours_fri_close,
                  :hours_sat_open, :hours_sat_close, :hours_sun_open, :hours_sun_close
    
    
    
    before_save :parse_hours
    
    def parse_hours
      h = Array.new
    
      if hours_mon_open.present? && hours_mon_close.present? && hours_mon_open.count == hours_mon_close.count
        h = Array.new
        i = 0
        while i < hours_mon_open.count
          hs = build_hours_set(hours_mon_open[i], hours_mon_close[i])
          h.push(hs) unless hs.nil?
          i += 1
        end
    
        if h.count > 0
          update_standard_hours_for("mon", h)
        end
      end
    
      if hours_tue_open.present? && hours_tue_close.present? && hours_tue_open.count == hours_tue_close.count
        h = Array.new
        i = 0
        while i < hours_tue_open.count
          hs = build_hours_set(hours_tue_open[i], hours_tue_close[i])
          h.push(hs) unless hs.nil?
          i += 1
        end
    
        if h.count > 0
          update_standard_hours_for("tue", h)
        end
      end
    
      if hours_wed_open.present? && hours_wed_close.present? && hours_wed_open.count == hours_wed_close.count
        h = Array.new
        i = 0
        while i < hours_wed_open.count
          hs = build_hours_set(hours_wed_open[i], hours_wed_close[i])
          h.push(hs) unless hs.nil?
          i += 1
        end
    
        if h.count > 0
          update_standard_hours_for("wed", h)
        end
      end
    
      if hours_thu_open.present? && hours_thu_close.present? && hours_thu_open.count == hours_thu_close.count
        h = Array.new
        i = 0
        while i < hours_thu_open.count
          hs = build_hours_set(hours_thu_open[i], hours_thu_close[i])
          h.push(hs) unless hs.nil?
          i += 1
        end
    
        if h.count > 0
          update_standard_hours_for("thu", h)
        end
      end
    
      if hours_fri_open.present? && hours_fri_close.present? && hours_fri_open.count == hours_fri_close.count
        h = Array.new
        i = 0
        while i < hours_fri_open.count
          hs = build_hours_set(hours_fri_open[i], hours_fri_close[i])
          h.push(hs) unless hs.nil?
          i += 1
        end
    
        if h.count > 0
          update_standard_hours_for("fri", h)
        end
      end
    
      if hours_sat_open.present? && hours_sat_close.present? && hours_sat_open.count == hours_sat_close.count
        h = Array.new
        i = 0
        while i < hours_sat_open.count
          hs = build_hours_set(hours_sat_open[i], hours_sat_close[i])
          h.push(hs) unless hs.nil?
          i += 1
        end
    
        if h.count > 0
          update_standard_hours_for("sat", h)
        end
      end
    
      if hours_sun_open.present? && hours_sun_close.present? && hours_sun_open.count == hours_sun_close.count
        h = Array.new
        i = 0
        while i < hours_sun_open.count
          hs = build_hours_set(hours_sun_open[i], hours_sun_close[i])
          h.push(hs) unless hs.nil?
          i += 1
        end
    
        if h.count > 0
          update_standard_hours_for("sun", h)
        end
      end
    end
    
    def build_hours_set(open, close)
      if open.present? && close.present?
        {"open" => open.to_s, "close" => close.to_s}
      else
        nil
      end
    end    
    
    def update_standard_hours_for(day, hours_array)
      if day.present? && hours_array.present?
        self.hours = Hash.new unless hours
        self.hours["standard"] = Hash.new unless hours["standard"]
        self.hours["standard"][day.to_s] = hours_array
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have data that has this kind of structure. Will be in ascending order by
I have about 30K records in an XML file and this file is updated
I have a database of 30k elements, each game names. I'm currently using: SELECT
In a database i have 30k users, each with a specified phonenumber. For each
I have a database of some 30k ranges, each is given as a pair
I have around 30K IP address(IPv4) in a MySQL Database. I want to get
I have a growing website with around 30k images in 4 sizes for a
have written this little class, which generates a UUID every time an object of
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
I have a large graph (30k vertices, 250m edges) and using boost graph library

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.