to_yaml中的引号不一致 foo.yml Ruby中的哈希输出的Yaml文件

简介

在下面的示例中,您可以看到标头和第1节和第11节已作为纯值放入yaml中,但是第2节和第8节已用单引号引起来。这似乎是在to_yaml阶段发生的,因为在哈希中,一切看起来都不错。 (我并不是简单地加载一个Yaml并将其转换回去,这只是为了简化示例)

我尝试过的

我尝试查看是否有任何特殊字符会引起混乱,但没有任何运气。例如,单词vehicle’s上有一个卷曲的撇号,而不是一个直的',但是在所有部分中都可以找到。第2节中的isn't带有单引号。我尝试在不同的部分中系统地添加/删除每种类型的撇号,以查看是否有什么不同,但这并没有

foo.yml

en:
  contract:
    terms_and_conditions:
      FF:
        company: Foo Foo SA
        spain_checkin_company: Foo Foo Spain SLR
        title: Rental Agreement
        header: "This Rental Agreement regulates the rental conditions between Foo Foo,hereinafter referred to as the Rental
                Firm,and the client,identified by a valid driving license,hereinafter referred to as the Hirer,and it is ruled by all the
                general and special conditions described in this agreement,unless there is any written derogation or alteration."
        column_1:
          section_1:
            title: 1. Vehicle conditions
            text: "1) The customer acknowledges having received the Vehicle and rented extras in a clean condition and with all the features working. 2) The customer will return the vehicle in a clean condition,with the same amount of fuel at the pick-up,and with all the vehicle’s features operating in a normal way,on the return date,time and location established in the Rental Agreement. Failure to meet these criteria will result in additional charges to the Hirer according to the rental firm price table. Any loss or damage in rented extras,equipment or spare parts,will be fully charged to the Hirer according to the Rental Firm price table."
          section_2:
            title: 2. Documents
            text: "A valid vehicle driver’s license,ID or Passport and credit card (Visa or Mastercard) are required and must be presented upon the vehicle’s collection and signing of the rental agreement. If the Hirer does not bring the necessary documents,the vehicle cannot be rented and regular no show fee will apply. 2) To hold a valid license to drive in Europe is the responsibility of the Hirer 3) The Hirer should be older than 18 years old. 4) If the Hirer is under 25 years of age,purchasing the Standard Insurance plan is mandatory,and he/she isn't allowed to purchase the Basic or Full Insurance plan when renting a vehicle.
 5) The credit card owner must be present at the vehicle´s collection.
  "
        column_2:
          section_8:
            title: 8. accident / Vehicle Damage
            text: "In the event of an accident or vehicle damage,the Hirer agrees to the following procedures: 1) Immediately notify the Rental Firm and police authorities of any accident,theft,robbery or other misfortune. 2) Take pictures and obtain names and addresses of all persons involved as well as witnesses,that can document what happened 3) Fill the accident report,together with other vehicles that may be involved. 4) Shall not leave the vehicle without taking all measures regarding its protection and . 5) Shall not take any responsibility or pled guilty,in the event of an accident that might hold the Rental Firm liable 6) Collect the accident report signed by all parties involved and the documents prepared by the police authorities,along with the vehicle keys,if retained (in case of vehicle theft) and send it immediately to the Rental firm. Otherwise,all insurances and coverage’s will expire,and the Hirer is liable for all expenses."
          section_11:
            title: 11. Liability / Security Deposit and After Rental Payments
            text: "1) The security deposit can only be paid by credit card (Visa or Mastercard),and the credit card owner must be present at the pick-up. At the vehicle delivery,the Hirer is required to pay the security deposit according to the chosen Insurance option. This amount will be held in the Hirer’s credit card to ensure the excess payment in the event of robbery or accident and any other vehicle damage during the rental period. 2) If the security deposit amount is not authorized by the bank or by the credit card owner,the contract cannot be executed and the vehicle cannot be delivered. In this case,the regular cancelation policy will apply and the full booking amount will be charged to the Hirer. The security deposit will be returned to the Hirer at the end of the rental period,after an inspection by a Rental Firm member staff,who shall state the vehicle is in similar conditions compared to when it was collected. 3) Vehicle damage and equipment/extras damage costs will be charged according to the Rental Firm price table. The Hirer will also be liable for the days not rented during the vehicle reasonable repair time,according to the damages at issue. 4) In case of an accident where the Hirer does not consider himself responsible,the Rental Firm will hold the full amount of the security deposit until the insurance company states the responsibility. 5) If the damage repair costs cannot be determined immediately,the Rental Firm will hold the full amount of the security deposit. A portion of the excess can be refunded in case the final damage repair costs are lower than the amount paid. 6) The Hirer agrees that the Rental Firm is authorized to charge the credit card on file for any further amounts that may arise such as wild camping,parking tickets,fines,traffic offence penalties,tolls,damages to the van (interior or exterior) and overdue amounts. Rental Firm is entitled to verify any of the damages to the van for 30 days after the last day of the rental agreement. In the event of a fine,the Rental Firm will always attempt to forward the fine to the Hirer. On these cases,a 25€ administrative fee will be charged by the Rental Firm. In the event that it is not possible to forward the fine to the Hirer,the Rental Firm will process the fine and charge to the Hirer the total cost of the fine plus VAT and an added administrative fee of 50€. 7) Hirer must provide the Rental Firm with an alternative credit card that can be used to meet Hirer’s obligations under the Rental Firm Terms and Conditions,in case of insufficient funds,declined transactions for any reason,and cancelled or suspended credit card. 8) All unpaid invoices will be added interest,which is the highest legal rate plus a flat fee,corresponding to 20% of the unpaid amount and any compensation for occurred damages / lost profits due by law. In the event of a legal dispute somehow related with this contract,the parties agree that the jurisdiction of the pick-up location will be applied."

Ruby中的哈希

foo = YAML.load(File.read("#{@PATH}foo.yml"))

=> {"en"=>
  {"contract"=>
    {"terms_and_conditions"=>
      {"FF"=>
        {"company"=>"Foo Foo SA","spain_checkin_company"=>"Foo Foo Spain SLR","title"=>"Rental Agreement","header"=>
          "This Rental Agreement regulates the rental conditions between Foo Foo,hereinafter referred to as the Rental Firm,and it is ruled by all the general and special conditions described in this agreement,unless there is any written derogation or alteration.","column_1"=>
          {"section_1"=>
            {"title"=>"1. Vehicle conditions","text"=>
              "1) The customer acknowledges having received the Vehicle and rented extras in a clean condition and with all the features working. 2) The customer will return the vehicle in a clean condition,will be fully charged to the Hirer according to the Rental Firm price table."},"section_2"=>
            {"title"=>"2. Documents","text"=>
              "A valid vehicle driver’s license,and he/she isn't allowed to purchase the Basic or Full Insurance plan when renting a vehicle. 5) The credit card owner must be present at the vehicle´s collection. "}},"column_2"=>
          {"section_8"=>
            {"title"=>"8. accident / Vehicle Damage","text"=>
              "In the event of an accident or vehicle damage,and the Hirer is liable for all expenses."},"section_11"=>
            {"title"=>"11. Liability / Security Deposit and After Rental Payments","text"=>
              "1) The security deposit can only be paid by credit card (Visa or Mastercard),the parties agree that the jurisdiction of the pick-up location will be applied."}}}}}}}

输出的Yaml文件

File.open("#{@PATH}foo.yml","w") do |f|
              YAML.dump(foo,f)
            end

(也用于f.puts foo.to_yaml),结果相同

en:
  contract:
    terms_and_conditions:
      FF:
        company: Foo Foo SA
        spain_checkin_company: Foo Foo Spain SLR
        title: Rental Agreement
        header: This Rental Agreement regulates the rental conditions between Foo
          Foo,identified
          by a valid driving license,and it
          is ruled by all the general and special conditions described in this agreement,unless there is any written derogation or alteration.
        column_1:
          section_1:
            title: 1. Vehicle conditions
            text: 1) The customer acknowledges having received the Vehicle and rented
              extras in a clean condition and with all the features working. 2) The
              customer will return the vehicle in a clean condition,with the same
              amount of fuel at the pick-up,and with all the vehicle’s features operating
              in a normal way,time and location established in
              the Rental Agreement. Failure to meet these criteria will result in
              additional charges to the Hirer according to the rental firm price table.
              Any loss or damage in rented extras,will
              be fully charged to the Hirer according to the Rental Firm price table.
          section_2:
            title: 2. Documents
            text: 'A valid vehicle driver’s license,ID or Passport and credit card
              (Visa or Mastercard) are required and must be presented upon the vehicle’s
              collection and signing of the rental agreement. If the Hirer does not
              bring the necessary documents,the vehicle cannot be rented and regular
              no show fee will apply. 2) To hold a valid license to drive in Europe
              is the responsibility of the Hirer 3) The Hirer should be older than
              18 years old. 4) If the Hirer is under 25 years of age,purchasing the
              Standard Insurance plan is mandatory,and he/she isn''t allowed to purchase
              the Basic or Full Insurance plan when renting a vehicle. 5) The credit
              card owner must be present at the vehicle´s collection. '
        column_2:
          section_8:
            title: 8. accident / Vehicle Damage
            text: 'In the event of an accident or vehicle damage,the Hirer agrees
              to the following procedures: 1) Immediately notify the Rental Firm and
              police authorities of any accident,robbery or other misfortune.
              2) Take pictures and obtain names and addresses of all persons involved
              as well as witnesses,that can document what happened 3) Fill the accident
              report,together with other vehicles that may be involved. 4) Shall
              not leave the vehicle without taking all measures regarding its protection
              and . 5) Shall not take any responsibility or pled guilty,in the event
              of an accident that might hold the Rental Firm liable 6) Collect the
              accident report signed by all parties involved and the documents prepared
              by the police authorities,if retained
              (in case of vehicle theft) and send it immediately to the Rental firm.
              Otherwise,and the Hirer
              is liable for all expenses.'
          section_11:
            title: 11. Liability / Security Deposit and After Rental Payments
            text: 1) The security deposit can only be paid by credit card (Visa or
              Mastercard),and the credit card owner must be present at the pick-up.
              At the vehicle delivery,the Hirer is required to pay the security deposit
              according to the chosen Insurance option. This amount will be held in
              the Hirer’s credit card to ensure the excess payment in the event of
              robbery or accident and any other vehicle damage during the rental period.
              2) If the security deposit amount is not authorized by the bank or by
              the credit card owner,the contract cannot be executed and the vehicle
              cannot be delivered. In this case,the regular cancelation policy will
              apply and the full booking amount will be charged to the Hirer. The
              security deposit will be returned to the Hirer at the end of the rental
              period,who shall
              state the vehicle is in similar conditions compared to when it was collected.
              3) Vehicle damage and equipment/extras damage costs will be charged
              according to the Rental Firm price table. The Hirer will also be liable
              for the days not rented during the vehicle reasonable repair time,according
              to the damages at issue. 4) In case of an accident where the Hirer does
              not consider himself responsible,the Rental Firm will hold the full
              amount of the security deposit until the insurance company states the
              responsibility. 5) If the damage repair costs cannot be determined immediately,the Rental Firm will hold the full amount of the security deposit. A
              portion of the excess can be refunded in case the final damage repair
              costs are lower than the amount paid. 6) The Hirer agrees that the Rental
              Firm is authorized to charge the credit card on file for any further
              amounts that may arise such as wild camping,damages to the van (interior or exterior)
              and overdue amounts. Rental Firm is entitled to verify any of the damages
              to the van for 30 days after the last day of the rental agreement. In
              the event of a fine,the Rental Firm will always attempt to forward
              the fine to the Hirer. On these cases,a 25€ administrative fee will
              be charged by the Rental Firm. In the event that it is not possible
              to forward the fine to the Hirer,the Rental Firm will process the fine
              and charge to the Hirer the total cost of the fine plus VAT and an added
              administrative fee of 50€. 7) Hirer must provide the Rental Firm with
              an alternative credit card that can be used to meet Hirer’s obligations
              under the Rental Firm Terms and Conditions,in case of insufficient
              funds,and cancelled or suspended
              credit card. 8) All unpaid invoices will be added interest,which is
              the highest legal rate plus a flat fee,corresponding to 20% of the
              unpaid amount and any compensation for occurred damages / lost profits
              due by law. In the event of a legal dispute somehow related with this
              contract,the parties agree that the jurisdiction of the pick-up location
              will be applied.
qq44461443 回答:to_yaml中的引号不一致 foo.yml Ruby中的哈希输出的Yaml文件

  • 第1栏第2节,文本包含尾随空格。
  • 第2栏第8节,文本包含一个:字符,后跟一个空格。

specification说:

  

纯白(未引用)样式没有识别指标,也没有提供任何转义形式。因此,它是最易读,最有限和最上下文相关的样式。 除了受限制的字符集外,普通标量不能为空,也不能包含前导或尾随空格字符。只有在空格字符被非字符包围的情况下,才能打破一条较长的普通行-空格。

     

...

     

普通标量绝对不能包含“:”和“#”字符组合。这样的组合将导致与映射键(值对和注释)产生歧义。另外,在内部流集合中,或当用作隐式键时,普通标量不得包含“ [”,“]”,“ {”,“}”和“,”字符。这些字符将与流收集结构产生歧义。

本文链接:https://www.f2er.com/3165238.html

大家都在问